public ActionResult Edit(PhrasesContextViewModel model) { if (!ModelState.IsValid) { SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Edit", "You have some validation errors."); if (Request.IsAjaxRequest()) { return(PartialView(model)); } return(View(model)); } SetViewBagsAndHeaders(Request.IsAjaxRequest(), "All added context", "Context is edited successfully."); model.DateChanged = DateTime.Now; model.UserId = User.Identity.GetUserId(); contextServices.Update(Mapper.Map <PhrasesContext>(model)); if (Request.IsAjaxRequest()) { return(PartialView("Index", contextServices.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).ProjectTo <PhrasesContextViewModel>())); } return(View("Index", contextServices.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).ProjectTo <PhrasesContextViewModel>())); }
public ActionResult Create(PhrasesContextViewModel model) { if (!ModelState.IsValid) { Response.Headers["InvalidModel"] = "false"; SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Add new context", "You have some validation errors."); if (Request.IsAjaxRequest()) { return(PartialView(model)); } return(View(model)); } if (User.Identity.GetActiveProject() == "0") { SetViewBagsAndHeaders(Request.IsAjaxRequest(), "Add new language", "You have to create project first."); ModelState.AddModelError("", "Create your first project and then you can add contexts."); if (Request.IsAjaxRequest()) { return(PartialView(model)); } return(View(model)); } SetViewBagsAndHeaders(Request.IsAjaxRequest(), "All added context", "New context is created successfully."); model.DateChanged = DateTime.Now; model.DateCreated = DateTime.Now; model.UserId = User.Identity.GetUserId(); model.IdProject = UserActiveProject; contextServices.Add(Mapper.Map <PhrasesContext>(model)); if (Request.IsAjaxRequest()) { return(PartialView("Index", contextServices.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).ProjectTo <PhrasesContextViewModel>())); } return(View("Index", contextServices.GetAllByIdProject(UserActiveProject, User.Identity.GetUserId()).ProjectTo <PhrasesContextViewModel>())); }