public MachinariesTypeViewModel FillViewModel(MachinariesTypeViewModel model = null)
        {
            if (model == null)
            {
                model = new MachinariesTypeViewModel();
            }
            model.Areas = dbManager.GetAll <OrderArea>().ToList();
            model.Types = dbManager.GetAll <MachineryType>().ToList();
            model.Title = model.Id > 0 ? "Редактирование" : "Добавление";

            return(model);
        }
Esempio n. 2
0
 public IActionResult Index(MachinariesTypeViewModel model)
 {
     if (!ModelState.IsValid)
     {
         model = typesManager.FillViewModel(model);
         dbManager.Commit();
         return(View("MachineryTypes", model));
     }
     model = typesManager.SaveOrUpdateMachineryType(model);
     dbManager.Commit();
     return(View("MachineryTypes", model));
 }
        internal MachinariesTypeViewModel GetMachineryTypesViewModel(int id = 0, MachinariesTypeViewModel model = null)
        {
            if (model == null)
            {
                model    = new MachinariesTypeViewModel();
                model.Id = id;
            }

            model = FillViewModel(model);
            var type = model.Id > 0 ?
                       dbManager.GetById <MachineryType>(model.Id) :
                       new MachineryType();

            model.CopyFrom(type);
            return(model);
        }
        internal MachinariesTypeViewModel SaveOrUpdateMachineryType(MachinariesTypeViewModel dto)
        {
            // validation

            var type = dto.Id > 0 ? dbManager.GetById <MachineryType>(dto.Id): new MachineryType();

            type.Name  = dto.Name;
            type.Areas = dbManager.GetByListId <OrderArea>(dto.AreasId).ToList();
            if (dto.Id == 0)
            {
                dbManager.AddAsync <MachineryType>(type);
            }

            var model = GetMachineryTypesViewModel(dto.Id);

            model.Message = "";

            return(model);
        }