public JsonResult EditGroup(GroupInfoVM model) { if (ModelState.IsValid) { try { Groups eFgroup = groupService.GetById(model.Id); eFgroup.Name = model.Name; eFgroup.Description = model.Description; eFgroup.DateAdded = DateTime.Now; eFgroup.DateModified = DateTime.Now; eFgroup.FkRefStatusId = (int)StatusEnum.Active; groupService.RemoveAllContacts(model.Id); // DBCONTEXT SAVE model.Contacts.ForEach(x => eFgroup.Contacts.Add(groupService.GetContactById(x.Id))); groupService.RemoveAllOrganisations(model.Id); // DBCONTEXT SAVE model.Organisations.ForEach(x => eFgroup.Organisations.Add(groupService.GetOrganisationById(x.Id))); groupService.Update(eFgroup); return(Json(new { status = CommonConstants.Ok, message = CommonConstants.AddedSuccessfully })); } catch (Exception e) { //throw; return(Json(new { status = CommonConstants.Error, message = CommonConstants.SomethingWentWrong })); } } else { return(Json(new { status = CommonConstants.Error, message = CommonConstants.FailedValidation })); } }
public ActionResult EditGroup(int id) { var eFGroup = groupService.GetById(id); var model = new GroupInfoVM(); model.Id = eFGroup.Id; model.Name = eFGroup.Name; model.Description = eFGroup.Description; model.Contacts = eFGroup.Contacts.Select(y => new SelectedContact { Id = y.Id, Name = y.FirstName + " " + y.LastName, Email = y.Email, JobTitle = y.JobTitle, Organisation = y.Organisations.Name }).ToList(); model.Organisations = eFGroup.Organisations.Select(y => new SelectedOrganisation { Id = y.Id, Name = y.Name, ContactCount = y.Contacts.Count, Country = y.Country }).ToList(); return(View(model)); }
public JsonResult AddGroup(GroupInfoVM model) { if (ModelState.IsValid) { try { //convert model to ef model Groups eFgroup = new Groups(); eFgroup.Name = model.Name; eFgroup.Description = model.Description; eFgroup.DateAdded = DateTime.Now; eFgroup.DateModified = DateTime.Now; eFgroup.FkRefStatusId = (int)StatusEnum.Active; model.Contacts.ForEach(x => eFgroup.Contacts.Add(groupService.GetContactById(x.Id))); model.Organisations.ForEach(x => eFgroup.Organisations.Add(groupService.GetOrganisationById(x.Id))); var group = groupService.Insert(eFgroup); return(Json(new { status = CommonConstants.Ok, message = CommonConstants.AddedSuccessfully })); } catch (Exception e) { throw; //return Json(new { status = CommonConstants.Error, message = CommonConstants.SomethingWentWrong }); } } else { return(Json(new { status = CommonConstants.Error, message = CommonConstants.FailedValidation })); } }
public ActionResult GroupInfo(int groupInfoId) { var groupInfo = GroupInfoService.GetByPK(groupInfoId); var model = new GroupInfoVM() { DenyAdd = !User.InRole(Role.TestAdmin), GetListUrl = Url.Action <GroupTestController>(c => c.GetGroupTests(groupInfoId, null)), EditUrl = Url.Action <GroupTestController>(c => c.EditGroupTest(groupInfoId, null)), Caption = "Тесты группы " + groupInfo.Group_ID }; if (User.InRole(Role.TestAdmin)) { model.DeleteUrl = Url.Action <GroupTestController>(c => c.DeleteGroupTest(null)); } AddColumns <GroupTest>(model, x => x.TestId); return(BaseView(new PagePart(PartialViewNames.AjaxList, model), new PagePart(new GroupInfoView { }.Init(groupInfo, Url).Get().ToString()))); }
public ActionResult AddGroup() { var model = new GroupInfoVM(); return(View(model)); }