private void Validate(WorkForm form, ModelStateDictionary modelState)
 {
     if (form.Description.IsNullOrEmpty())
     {
         modelState.AddModelError("Form.Description", "Поле не может быть пустым");
     }
 }
        public void HandleEdit(WorkForm form, WorkValidationResult valResult)
        {
            var work = valResult.Work;

            work.Description = form.Description;
            work.EngineType  = form.EngineType;

            entityRepository.SaveChanges();
        }
        public Guid HandleCreate(WorkForm form)
        {
            var work = workFactory.Create(form.Description, form.EngineType);

            entityRepository.InsertOnSave(work);
            entityRepository.SaveChanges();

            return(work.Id);
        }
Ejemplo n.º 4
0
        public WorkEditModel BuildEdit(Guid id)
        {
            var work = workRepository.Find(id);

            var form = new WorkForm()
            {
                Description = work.Description,
                EngineType  = work.EngineType
            };

            return(new WorkEditModel(id, form, engineTypesListModelBuilder.Build()));
        }
        public WorkValidationResult ValidateOnEdit(Guid id, WorkForm form, ModelStateDictionary modelState)
        {
            Validate(form, modelState);

            var work = workRepository.Find(id);

            if (work == null)
            {
                throw new Exception("Работа не найдена");
            }

            return(new WorkValidationResult(modelState, work));
        }
        public WorkValidationResult ValidateOnCreate(WorkForm form, ModelStateDictionary modelState)
        {
            Validate(form, modelState);

            return(new WorkValidationResult(modelState, new Work()));
        }
 public WorkEditModel(Guid?id, WorkForm form, IList <SelectListItem> engineTypesList)
 {
     Id              = id;
     Form            = form;
     EngineTypesList = engineTypesList;
 }
Ejemplo n.º 8
0
 public WorkEditModel BuildByForm(Guid?id, WorkForm form)
 {
     return(new WorkEditModel(id, form, engineTypesListModelBuilder.Build()));
 }