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()); }
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); }
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)); }
private void PhoneGrid_OnBtnCreateClicked(object sender, EventArgs e) { var model = new PhoneEditViewModel(); this.FormCreaterCreate.CreateForm(model); }