public static string UpdateAdminList(List <AdminMasterModal> data) { using (var context = new SalesReturndbEntities()) { using (TransactionScope transaction = new TransactionScope()) { foreach (var Obj in data) { //CommonDAL.CheckIfEmployeeExist(Obj.VPName); var duplicateCheck = context.TblAdminMasters.Where(x => x.Admin_Id == Obj.Admin_Id && x.IsActive == true).FirstOrDefault(); if (duplicateCheck != null) { var duplicateCheckValue = context.TblAdminMasters.Where(x => x.EmployeeCode == Obj.EmployeeCode && x.Admin_Id != Obj.Admin_Id && x.IsActive == true).FirstOrDefault(); if (duplicateCheckValue == null) { duplicateCheck.EmployeeCode = Obj.EmployeeCode; duplicateCheck.ModifiedBy = Obj.CreatedBy; duplicateCheck.ModifiedDate = DateTime.Now; context.Entry(duplicateCheck).State = EntityState.Modified; context.SaveChanges(); } } else { var duplicateCheckValue = context.TblAdminMasters.Where(x => x.EmployeeCode == Obj.EmployeeCode && x.IsActive == true).FirstOrDefault(); if (duplicateCheckValue == null) { TblAdminMaster marix = new TblAdminMaster() { EmployeeCode = Obj.EmployeeCode, IsActive = true, CreatedBy = Obj.CreatedBy, CreatedDate = DateTime.Now, }; context.Entry(marix).State = EntityState.Added; context.SaveChanges(); } } } transaction.Complete(); transaction.Dispose(); } return("Success : Admin list successfully updated."); } }
public bool AdminInsert(AdminModel model) { TblAdminMaster obj = new TblAdminMaster(); obj.Admin1 = model.Admin1; obj.Admin2 = model.Admin2; obj.Admin3 = model.Admin3; obj.Admin4 = model.Admin4; obj.Admin5 = model.Admin5; obj.Description = model.Description; obj.Name = model.Name; dbcontext.TblAdminMasters.Add(obj); dbcontext.SaveChanges(); return(true); }