using LHDN.CRM.Models.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LHDN.CRM.BC.Repositories
{
    public class AuditRepository : BaseRepository<CRMContext, AuditMaster>
    {
        public long SaveAudit(AuditMaster model)
        {
            try
            {
                Add(model);
                Save();
            }
            catch (DbEntityValidationException e)
            {
                string strErr = "";
                foreach (var eve in e.EntityValidationErrors)
                {

                    strErr += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        strErr += String.Format("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                string strError = ex.Message;
            }
            return model.AuditID;
        }
    }
}
