// GET: Users/Create public ActionResult Create() { ViewBag.CityId = new SelectList( ComBoxHelpers. GetCities(), "CityId", "NameCity"); ViewBag.CompanyId = new SelectList( ComBoxHelpers. GetCompanies(), "CompanyId", "NameCompany"); ViewBag.StateId = new SelectList( ComBoxHelpers. GetStates(), "StateId", "NameState"); return(View()); }
// GET: Companies/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult( HttpStatusCode.BadRequest)); } var company = db.Companies.Find(id); if (company == null) { return(HttpNotFound()); } ViewBag.CityId = new SelectList( ComBoxHelpers. GetCities(), "CityId", "NameCity", company.CityId); ViewBag.StateId = new SelectList( ComBoxHelpers. GetStates(), "StateId", "NameState", company.StateId); return(View(company)); }
public ActionResult Create(Company company) { if (ModelState.IsValid) { db.Companies.Add(company); try { db.SaveChanges(); if (company.LogoFile != null) { var folder = "~/Content/Logos"; var file = string.Format("{0}.jpg", company.CompanyId); var response = FilesHelpers. UploadPhoto( company.LogoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); company.Logo = pic; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException. InnerException != null && ex.InnerException. InnerException.Message. Contains("_Index")) { ModelState. AddModelError( string.Empty, "You Can't Add a New Record, Because There is Already One"); } else { ModelState. AddModelError( string.Empty, ex.Message); } } } ViewBag.CityId = new SelectList( ComBoxHelpers. GetCities(), "CityId", "NameCity", company.CityId); ViewBag.StateId = new SelectList( ComBoxHelpers. GetStates(), "StateId", "NameState", company.StateId); return(View(company)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { if (user.PhotoFile != null) { var folder = "~/Content/Photos"; var pic = string.Empty; var file = string.Format("{0}.jpg", user.UserID); var response = FilesHelpers. UploadPhoto( user.PhotoFile, folder, file); if (response) { pic = string.Format("{0}/{1}", folder, user.UserID); user.Photo = pic; } } var db2 = new CECommerceContext(); var currentUser = db2.Users.Find(user.UserID); if (currentUser.UserName != null) { UsersHelpers.UpdateUserName(currentUser.UserName, user.UserName); } db2.Dispose(); db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException. InnerException != null && ex.InnerException. InnerException.Message. Contains("_Index")) { ModelState. AddModelError( string.Empty, "You Can't Add a New Record, Because There is Already One"); } else { ModelState. AddModelError( string.Empty, ex.Message); } } } ViewBag.CityId = new SelectList( ComBoxHelpers. GetCities(), "CityId", "NameCity", user.CityId); ViewBag.CompanyId = new SelectList( ComBoxHelpers. GetCompanies(), "CompanyId", "NameCompany", user.CompanyId); ViewBag.StateId = new SelectList( ComBoxHelpers. GetStates(), "StateId", "NameState", user.StateId); return(View(user)); }