public ActionResult Edit(int id, GroupViewModel groupViewModel) { try { // TODO: Add update logic here if (ModelState.IsValid) { Group group = new Group() { GroupId = id, GroupName = groupViewModel.GroupName, //Password = groupViewModel.Password, //CreatedBy = groupViewModel.CreatedBy, //CreatedDate = groupViewModel.CreatedDate, Status = groupViewModel.Status, //ModifiedBy = groupViewModel.ModifiedBy, //ModifiedDate = groupViewModel.ModifiedDate, }; db.Entry(group).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(groupViewModel); } catch { return View(); } }
public ActionResult ChangeStatus(int id, ChangeStatusViewModel changeStatusViewModel) { if (db.Groups.Find(id).CreatedBy != HttpContext.User.Identity.Name) { return RedirectToAction("Index"); } if (db.Groups.Find(id) != null) { Group group = new Group() { GroupId = id, Status = changeStatusViewModel.Status, }; db.Entry(group).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return new HttpNotFoundResult(); }
public ActionResult Create(GroupViewModel groupViewModel) { try { // TODO: Add insert logic here if (ModelState.IsValid) { Group group = new Group() { GroupName = groupViewModel.GroupName, //Password = groupViewModel.Password, //CreatedBy = groupViewModel.CreatedBy, //CreatedDate = groupViewModel.CreatedDate, Status = groupViewModel.Status, //ModifiedBy = groupViewModel.ModifiedBy, //ModifiedDate = groupViewModel.ModifiedDate, }; db.Groups.Add(group); //db.SaveChanges(); if (!(bool)Session["isAdmin"]) { GroupsUsers groupsUsers = new GroupsUsers() { GroupId = group.GroupId, UserId = (int)HttpContext.Session["UserId"], }; db.GroupUserRelations.Add(groupsUsers); } db.SaveChanges(); //IdentityManager im = new IdentityManager(); //ApplicationUser user = new ApplicationUser() { UserName = group.GroupName, }; //im.CreateUser(user, group.Password); return RedirectToAction("AddMember", new { id=group.GroupId}); } return View(groupViewModel); } catch { return View(); } }