コード例 #1
0
        public IActionResult Update(PhoneEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Phone phone = _phoneRepository.GetPhone(model.Id);
                phone.Name      = model.Name;
                phone.Type      = model.Type;
                phone.Color     = model.Color;
                phone.Price     = model.Price;
                phone.Dimension = model.Dimension;
                if (model.Photo != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    phone.PhotoPath = ProcessUploadedFile(model);
                }

                _phoneRepository.Update(phone);
                return(RedirectToAction("index"));
            }
            return(View());
        }
コード例 #2
0
        void PhoneGrid_OnBtnEditClicked(object sender, EventArgs e)
        {
            int id    = int.Parse(((Button)sender).CommandArgument);
            var model = new PhoneEditViewModel();

            this.GetById(id, ref model);
            this.FormCreaterEdit.CreateForm(model);
        }
コード例 #3
0
        public ViewResult Edit(int id)
        {
            Phone phone = _phoneRepository.GetPhone(id);
            PhoneEditViewModel phoneEditViewModel = new PhoneEditViewModel
            {
                Id                = phone.Id,
                Name              = phone.Name,
                Type              = phone.Type,
                Color             = phone.Color,
                Dimension         = phone.Dimension,
                Price             = phone.Price,
                ExistingPhotoPath = phone.PhotoPath
            };

            return(View(phoneEditViewModel));
        }
コード例 #4
0
        private void PhoneGrid_OnBtnCreateClicked(object sender, EventArgs e)
        {
            var model = new PhoneEditViewModel();

            this.FormCreaterCreate.CreateForm(model);
        }