public ActionResult Create(Company company) { if (ModelState.IsValid) { db.Companies.Add(company); db.SaveChanges(); if (company.LogoFile != null) { var folder = "~/Content/Logos"; var file = string.Format("{0}.jpg", company.CompanyId); var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}.jpg", folder, company.CompanyId); company.Logo = pic; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", company.CityId); ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", company.CountryId); return(View(company)); }
public ActionResult EditCity(City city) { if (ModelState.IsValid) { try { db.Entry(city).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (!response.Succedeed) { ModelState.AddModelError(string.Empty, response.Message); } return(RedirectToAction($"{nameof(Details)}/{city.CountryId}")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(city)); }
public ActionResult Edit(Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succedeed) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", customer.CityId); ViewBag.CountryId = new SelectList(CombosHelper.GetCountries(), "CountryId", "Name", customer.CountryId); return(View(customer)); }