public bool SaveType(EditTypeModel model) { try { if (!ValidateModel(model)) return false; var type = new EmployeeDocumentType(); if (model.Id > 0) type = EmployeeDocumentTypeDao.Load(model.Id); type.Name = model.Name.Trim(); EmployeeDocumentTypeDao.MergeAndFlush(type); return true; } catch (Exception ex) { Log.Error("Exception", ex); model.Error = "Исключение: " + ex.GetBaseException().Message; return false; } }
public void GetEditTypeModel(EditTypeModel model) { if (model.Id <= 0) return; EmployeeDocumentType type = EmployeeDocumentTypeDao.Load(model.Id); model.Name = type.Name; }
public ContentResult SaveType(int id, string name) { bool saveResult; string error; try { var model = new EditTypeModel { Id = id, Name = name}; saveResult = AdminBl.SaveType(model); error = model.Error; } catch (Exception ex) { Log.Error("Exception on SaveType:", ex); error = ex.GetBaseException().Message; saveResult = false; } JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult }); return Content(jsonString); }
protected bool ValidateModel(EditTypeModel model) { if (string.IsNullOrEmpty(model.Name) || string.IsNullOrEmpty(model.Name.Trim())) { model.Error = "Название - обязательное поле."; return false; } if (EmployeeDocumentTypeDao.IsTypeWithNameAndOtherIdExists(model.Name.Trim(), model.Id)) { model.Error = "Название типа заявки должно быть уникальным."; return false; } return true; }
public ActionResult EditTypeDialog(int Id) { try { EditTypeModel model = new EditTypeModel { Id = Id }; AdminBl.GetEditTypeModel(model); return PartialView(model); } catch (Exception ex) { Log.Error("Exception",ex); string error = "Ошибка при загрузке данных: " + ex.GetBaseException().Message; return PartialView("DialogError", new DialogErrorModel {Error = error}); } }