public int Delete(HolidaysAttendance HolidayAttendance, int UserIdentity) { try { using (var db = new HCMEntities()) { HolidaysAttendance HolidayAttendanceObj = db.HolidaysAttendance.SingleOrDefault(x => x.HolidayAttendanceID.Equals(HolidayAttendance.HolidayAttendanceID)); HolidayAttendanceObj.HolidaysAttendanceDetails.ToList().ForEach(d => db.HolidaysAttendanceDetails.Remove(d)); db.HolidaysAttendance.Remove(HolidayAttendanceObj); return(db.SaveChanges(UserIdentity)); } } catch { throw; } }
public int Update(HolidaysAttendance HolidayAttendance) { try { using (var db = new HCMEntities()) { HolidaysAttendance HolidayAttendanceObj = db.HolidaysAttendance.SingleOrDefault(x => x.HolidayAttendanceID.Equals(HolidayAttendance.HolidayAttendanceID)); HolidayAttendanceObj.HolidayAttendanceID = HolidayAttendance.HolidayAttendanceID; HolidayAttendanceObj.HolidaySettingID = HolidayAttendance.HolidaySettingID; HolidayAttendanceObj.OrganizationID = HolidayAttendance.OrganizationID; HolidayAttendanceObj.LastUpdatedDate = HolidayAttendance.LastUpdatedDate; HolidayAttendanceObj.LastUpdatedBy = HolidayAttendance.LastUpdatedBy; return(db.SaveChanges()); } } catch { throw; } }
public int Insert(HolidaysAttendance HolidayAttendance) { try { using (var db = new HCMEntities()) { db.HolidaysAttendance.Add(HolidayAttendance); db.SaveChanges(); return(HolidayAttendance.HolidayAttendanceID); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("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) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }