Пример #1
0
        public ActionResult Update(PumpViewModel model)
        {
            var entityExists = _pumpService.CheckIfExists(model.Id);

            if (!entityExists)
            {
                TempData[TempDataErrorKey] = "Насос с таким id не сушествует";

                return(RedirectToAction("Index", "Admin"));
            }

            if (model.ImageInput == null && model.PumpImage == null)
            {
                ModelState.AddModelError("ImageInput", "Укажите картинку");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UpdateImage(model);

            var dto = _mapper.Map <PumpViewModel, Pump>(model);

            _pumpService.Update(dto);

            TempData[TempDataMessageKey] = "Насос был обновлен";

            return(RedirectToAction("Index", "Admin"));
        }
Пример #2
0
        public ActionResult Create(int categoryId)
        {
            var model = new PumpViewModel
            {
                PumpCategoryId = categoryId
            };

            return(View(model));
        }
Пример #3
0
 public void LoadCellValues(PumpViewModel pump)
 {
     ExceptionUtility.Try(() =>
     {
         this._pump           = pump;
         this._textLabel.Text = pump.Text;
         this._textLabel.SizeToFit();
         this._checkbox.SetChecked(this._pump.Selected);
     });
 }
Пример #4
0
        public bool ShowView(BaseDevice device)
        {
            vm = new PumpViewModel(device as Pump);
            this.DataContext = vm;
            this.ShowDialog();

            Debug.WriteLine("edit end");

            if (vm.isSaved)
            {
                vm.Entity.ClonePropertiesTo(device);
            }
            return(vm.isSaved);
        }
Пример #5
0
        public ActionResult Create(PumpViewModel model)
        {
            if (model.ImageInput == null)
            {
                ModelState.AddModelError("ImageInput", "Укажите картинку");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UpdateImage(model);

            var entity = _mapper.Map <PumpViewModel, Pump>(model);

            _pumpService.Add(entity);

            TempData[TempDataMessageKey] = "Новый насос был добавлен";

            return(RedirectToAction("Index", "Admin"));
        }
Пример #6
0
        private void UpdateImage(PumpViewModel model)
        {
            if (model.ImageInput == null)
            {
                return;
            }

            var image = new ImageViewModel
            {
                Id       = model.Id,
                Name     = model.ImageInput.FileName,
                MimeType = model.ImageInput.ContentType
            };

            using (var br = new BinaryReader(model.ImageInput.InputStream))
            {
                image.Data = br.ReadBytes(model.ImageInput.ContentLength);
            }

            model.PumpImage  = image;
            model.ImageInput = null;
        }