/// <summary> /// creates a new reminder of type employee /// </summary> /// <param name="reminder">new reminders data</param> public static void Create(EmployeeRemindersViewModel reminder) { try { RemindersEntities Entities = new RemindersEntities(); //.Where(x => x.Email == reminder.Email) var items = Entities.Reminders.ToList(); //if (items.Count < 1) //{ Reminder entity = new Reminder(); entity.ID = reminder.ID; entity.Name = reminder.Name; entity.Email = reminder.Email; entity.BirthDate = reminder.BirthDate; entity.PositionID = reminder.PositionID; entity.IsActive = reminder.IsActive; entity.Image = null; entity.StartDate = reminder.StartDate.Value; entity.EmployeeID = reminder.EmployeeID; entity.CreatedBy = reminder.CreatedBy; entity.CreatedOn = DateTime.Now; entity.TypeID = LookupService.GetLookupIdByCode((int)Lookups.employee); Entities.Reminders.Add(entity); Entities.SaveChanges(); reminder.ID = entity.ID; foreach (var x in reminder.SelectedGroupsID) { Entities.RemindersGroups.Add(new RemindersGroup { GroupID = x, ReminderID = entity.ID, CreatedOn = DateTime.Now, CreatedBy = 1, ModifyOn = DateTime.Now, ModifyBy = 1 }); Entities.SaveChanges(); } //} //else //{ //} } catch (Exception ex) { throw ex; } }
/// <summary> /// method to edit the reminder of type employee /// </summary> /// <param name="reminder">edited data of reminder</param> public static void EmployeeReminderUpdate(EmployeeRemindersViewModel reminder, HttpPostedFileBase image1) { try { RemindersEntities Entities = new RemindersEntities(); Reminder entity = Entities.Reminders.Find(reminder.ID); entity.Name = reminder.Name; entity.Email = reminder.Email; entity.BirthDate = reminder.BirthDate; entity.PositionID = reminder.PositionID; entity.IsActive = reminder.IsActive; entity.Image = null; if (reminder.ImagePath != null) { entity.ImagePath = reminder.ImagePath; } entity.StartDate = reminder.StartDate.Value; entity.EmployeeID = reminder.EmployeeID; entity.ModifyBy = reminder.ModifyBy; entity.ModifyOn = reminder.ModifyOn; entity.CreatedBy = reminder.CreatedBy; entity.TypeID = LookupService.GetLookupIdByCode((int)Lookups.employee); Entities.SaveChanges(); foreach (var x in reminder.SelectedGroupsID)//************?????? { Entities.RemindersGroups.Add(new RemindersGroup { GroupID = x, ReminderID = entity.ID, ModifyOn = DateTime.Now, ModifyBy = 1, CreatedOn = DateTime.Now, CreatedBy = 1 }); Entities.SaveChanges(); } } catch (Exception ex) { throw ex; } }
/// <summary> /// creates a new reminder of type general /// </summary> /// <param name="reminder">new reminders data</param> public static void Create(GeneralRemindersViewModel reminder) { try { RemindersEntities Entities = new RemindersEntities(); Reminder entity = new Reminder(); entity.ID = reminder.ID; entity.Name = reminder.Name; entity.IsActive = reminder.IsActive; entity.Image = null; entity.StartDate = reminder.StartDate.Value; entity.EndDate = reminder.EndDate; entity.BreifDescription = reminder.BreifDescription; entity.Time = reminder.Time; entity.CreatedOn = reminder.CreatedOn.Value; entity.CreatedBy = reminder.CreatedBy; entity.TypeID = LookupService.GetLookupIdByCode((int)Lookups.general); Entities.Reminders.Add(entity); Entities.SaveChanges(); reminder.ID = entity.ID; foreach (var x in reminder.SelectedGroupsID) { Entities.RemindersGroups.Add(new RemindersGroup { GroupID = x, ReminderID = entity.ID, CreatedOn = DateTime.Now, CreatedBy = 1, ModifyOn = DateTime.Now, ModifyBy = 1 }); Entities.SaveChanges(); } } catch (Exception ex) { throw ex; } }