/// //////////////////////////////////////////////// public static void Create(EmployeesGroupsViewModel group) { try { RemindersEntities Entities = new RemindersEntities(); var entity = new Group(); //entity.ID = group.ID; entity.Name = group.Name; entity.ModifyOn = group.ModifyOn; entity.CreatedOn = group.CreatedOn; entity.ModifyBy = group.ModifyBy; entity.CreatedBy = group.CreatedBY; Entities.Groups.Add(entity); Entities.SaveChanges(); group.ID = entity.ID; foreach (var x in group.SelectedEmployeesID) { Entities.EmployeesGroups.Add(new EmployeesGroup { EmployeeID = x, GroupID = entity.ID, CreatedOn = DateTime.Now, CreatedBY = 1, ModifyOn = DateTime.Now, ModifyBy = 1 }); Entities.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public ActionResult EditInfo(int id) { EmployeesGroupsViewModel EmpGroup = GroupService.EmployeeGroupsGetByID(id); EmpGroup.Employees = GroupService.GetAllEmployee(); return(View(EmpGroup)); }
///////////////////////////////////////////////////////// public static void EditGroup(EmployeesGroupsViewModel EmpGroup) { try { RemindersEntities Entities = new RemindersEntities(); Group entity = Entities.Groups.Find(EmpGroup.ID); entity.Name = EmpGroup.Name; //entity.ModifyOn = EmpGroup.ModifyOn; //entity.CreatedOn = EmpGroup.CreatedOn; //entity.ModifyBy = EmpGroup.ModifyBy; //entity.CreatedBy = EmpGroup.CreatedBY; //;; Entities.Groups.Attach(entity); Entities.Entry(entity).State = EntityState.Modified; Entities.SaveChanges(); //;;;;; var list = entity.EmployeesGroups; Entities.EmployeesGroups.RemoveRange(list); Entities.SaveChanges(); foreach (var x in EmpGroup.SelectedEmployeesID) { Entities.EmployeesGroups.Add(new EmployeesGroup { EmployeeID = x, GroupID = entity.ID, CreatedOn = DateTime.Now, CreatedBY = 1, ModifyOn = DateTime.Now, ModifyBy = 1 }); Entities.SaveChanges(); } } catch (Exception ex) { throw ex; } }
//////////////////////////////////////// public static EmployeesGroupsViewModel EmployeeGroupsGetByID(int id) { using (RemindersEntities db = new RemindersEntities()) { Group groups = db.Groups.Where(x => x.ID == id).FirstOrDefault(); EmployeesGroupsViewModel EmployeegroupInfo = new EmployeesGroupsViewModel() { ID = groups.ID, GroupID = groups.ID, Name = groups.Name, SelectedEmployeesID = groups.EmployeesGroups.Select(x => x.EmployeeID).ToArray() }; EmployeegroupInfo.Employeelist = new List <EmployeesViewModel>(); foreach (var emp in groups.EmployeesGroups) { EmployeegroupInfo.Employeelist.Add(new EmployeesViewModel { Name = emp.Employee.Name }); } return(EmployeegroupInfo); } }
public ActionResult Create() { //return View(/*GroupService.GetAllEmployee()*/); EmployeesGroupsViewModel group = new EmployeesGroupsViewModel(); group.Employees = GroupService.GetAllEmployee(); return(View(group)); }
public ActionResult EditInfo(EmployeesGroupsViewModel EmpGroup) { EmpGroup.CreatedOn = DateTime.Now; EmpGroup.ModifyOn = DateTime.Now; EmpGroup.CreatedBY = 1; EmpGroup.ModifyBy = 1; GroupService.EditGroup(EmpGroup); RouteValueDictionary routeValues = this.GridRouteValues(); return(RedirectToAction("Groups", routeValues)); }
public ActionResult Create(EmployeesGroupsViewModel group) { if (ModelState.IsValid) { group.CreatedOn = DateTime.Now; group.ModifyOn = DateTime.Now; group.CreatedBY = 1; group.ModifyBy = 1; GroupService.Create(group); RouteValueDictionary GrouprouteValues = this.GridRouteValues(); return(RedirectToAction("Groups", GrouprouteValues)); } //The model is invalid - render the current view to show any validation errors return(View(group)); }
///////////////////////////////////////////////////// public static void Delete(EmployeesGroupsViewModel group) { try { //DeleteEmployeesGroups(group); RemindersEntities Entities = new RemindersEntities(); Group entity = Entities.Groups.Find(group.ID); var list = entity.EmployeesGroups; Entities.EmployeesGroups.RemoveRange(list); Entities.SaveChanges(); Entities.Groups.Remove(entity); Entities.SaveChanges(); } catch (Exception ex) { throw ex; } }
////////////////////////////////////////////////////// public static bool Noselecteditem(EmployeesGroupsViewModel group) { /////////////////////////////////////////////////// //var list = group.SelectedEmployeesID.ToList(); var list = group.Employees.ToList(); if (list != null) { if (list.Count != 0) { return(true); } else { return(false); } } else { return(false); } }
public ActionResult Delete(EmployeesGroupsViewModel group) { GroupService.Delete(group); RedirectToAction("Groups"); return(View("Groups", GroupService.Read())); }