public ActionResult EditPartial(Int64 id) { bool has_error = false; ServiceActionViewModel model = null; try { var action = ActionService.GetActionById(id); if (action == null) { ModelState.AddModelError("", "Работа не найдена"); has_error = true; } model = ServiceActionModelConverter.ToModel(action); model.IsItInDialog = true; } catch (DomainException e) { ModelState.AddModelError("", e); has_error = true; } if (has_error) { return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId })); } PrepareForCreate(); return(PartialView("_Edit", model)); }
public ActionResult Delete(int id) { var action_srv = CompositionRoot.Resolve <IActionService>(); bool has_error = false; ServiceActionViewModel model = null; try { var action = action_srv.GetActionById(id); if (action == null) { ModelState.AddModelError("", "Работа не найдена"); has_error = true; } model = ServiceActionModelConverter.ToModel(action); } catch (DomainException e) { ModelState.AddModelError("", e); has_error = true; } if (has_error) { return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId })); } return(View(model)); }
public ActionResult Edit(ServiceActionViewModel model) { bool has_error = false; string errorMessage = string.Empty; if (ModelState.IsValid) { try { var action = ActionService.GetActionById(model.Id); if (action == null) { throw new DomainException($"Прием с идентификатором {model.Id} не найден в базе данных"); } ServiceActionModelConverter.FromModel(model, action); if (action.ServiceChild != null && !Equals(action.Service.Id, action.ServiceChild.Parent.Id)) { throw new DomainException("Подуслуга не связана с услугой"); } ActionService.Update(action); } catch (DomainException e) { ModelState.AddModelError("", e.Message); errorMessage = e.Message; has_error = true; } catch (Exception e) { if (!model.IsItInDialog) { throw e; } Logger.Error(e); errorMessage = $"Ошибка при сохранении данныхъ {e.Message}"; has_error = true; } if (!has_error && !model.IsItInDialog) { return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId })); } } PrepareForCreate(); if (model.IsItInDialog) { if (!has_error) { return(Json(true)); } return(Json(new { message = errorMessage })); } return(View(model)); }
public ActionResult GetById(Int64 id) { var action = ActionService.GetActionById(id); if (action == null) { return(Json(false, JsonRequestBehavior.AllowGet)); } return(Json(ServiceActionModelConverter.ToModel(action), JsonRequestBehavior.AllowGet)); }