public int Delete(int PromotionPeriodID, int UserIdentity) { try { using (var db = new HCMEntities()) { PromotionsPeriods PromotionsPeriodObj = db.PromotionsPeriods.SingleOrDefault(x => x.PromotionPeriodID.Equals(PromotionPeriodID)); db.PromotionsPeriods.Remove(PromotionsPeriodObj); return(db.SaveChanges(UserIdentity)); } } catch { throw; } }
public int Update(PromotionsPeriods PromotionsPeriod) { try { using (var db = new HCMEntities()) { PromotionsPeriods PromotionsPeriodObj = db.PromotionsPeriods.SingleOrDefault(x => x.PromotionPeriodID.Equals(PromotionsPeriod.PromotionPeriodID)); PromotionsPeriodObj.PeriodID = PromotionsPeriod.PeriodID; PromotionsPeriodObj.YearID = PromotionsPeriod.YearID; PromotionsPeriodObj.PromotionStartDate = PromotionsPeriod.PromotionStartDate; PromotionsPeriodObj.PromotionEndDate = PromotionsPeriod.PromotionEndDate; PromotionsPeriodObj.IsActive = PromotionsPeriod.IsActive; PromotionsPeriodObj.LastUpdatedDate = PromotionsPeriod.LastUpdatedDate; PromotionsPeriodObj.LastUpdatedBy = PromotionsPeriod.LastUpdatedBy; return(db.SaveChanges()); } } catch { throw; } }
public int Insert(PromotionsPeriods PromotionsPeriod) { try { using (var db = new HCMEntities()) { db.PromotionsPeriods.Add(PromotionsPeriod); db.SaveChanges(); return(PromotionsPeriod.PromotionPeriodID); } } 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; } }