public ActionResult Edit([Bind(Include = "CompanyId,Name,ProvinceId,DepartamentId,CityId,AddressO,AddressL,Locality,Logo,LogoFile,PartitaIva,CodiceFiscale,Phone,PhoneMobil,Fax,Email,http")] Company company, HttpPostedFileBase LogoFile) { if (ModelState.IsValid) { try { if (company.LogoFile != null) { var folder = "~/Content/Logos"; var file = string.Format("{0}.jpg", company.CompanyId); var response = FilesHelper.UploadPhoto(LogoFile, folder, file, company.Logo); //var response = FilesHelper.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) { ModelState.AddModelError(string.Empty, ex.Message); } } ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", company.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", company.ProvinceId); ViewBag.CityId = new SelectList(DropDownHelper.GetCities(), "CityId", "Name", company.CityId); return(View(company)); }
// GET: Companies/Create public ActionResult Create() { ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name"); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name"); ViewBag.CityId = new SelectList(DropDownHelper.GetCities(), "CityId", "Name"); return(View()); }
// GET: Provinces/Create public ActionResult Create() { //add order by "combobox ViewBag.DepartamentId = new SelectList( DropDownHelper.GetDepartaments(), "DepartamentId", "Name"); return(View()); }
public ActionResult Create([Bind(Include = "UserId,UserName,FirstName,LastName,DateBirth,Phone,Address,Photo,PhotoFile,DepartamentId,ProvinceId,CityId,CompanyId")] User user, HttpPostedFileBase PhotoFile) { if (ModelState.IsValid) { //?dupplicati if (db.Users.Any(u => u.UserName.Equals(user.UserName) && u.CompanyId.Equals(user.CompanyId))) { ModelState.AddModelError(string.Empty, "Esiste già un Registro con lo stesso valore"); } else { db.Users.Add(user); try { db.SaveChanges(); //attention Role User UsersHelper.CreateUserAsp(user.UserName, "User"); if (user.PhotoFile != null) { var folder = "~/Content/Users"; //can be extention png,jpeg,gif,jpg var file = string.Format("{0}.jpg", user.UserId); //var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); var response = FilesHelper.UploadPhoto(PhotoFile, folder, file, user.Photo); if (response) { if (response) { var pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } } return(RedirectToAction("Index")); } catch (Exception ex) { //ModelState.AddModelError(string.Empty, ex.Message); ModelState.AddModelError(string.Empty, ex.Message + " NON RIESCO A SALVARE - User Duplicato"); } } } ViewBag.CityId = new SelectList(DropDownHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(DropDownHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", user.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", user.ProvinceId); return(View(user)); }
public ActionResult Edit([Bind(Include = "CustomerId,UserName,FirstName,LastName,DateBirth,Phone,Address,DepartamentId,ProvinceId,CityId")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(DropDownHelper.GetCities(), "CityId", "Name", customer.CityId); ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", customer.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", customer.ProvinceId); return(View(customer)); }
// GET: Cities/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } City city = db.Cities.Find(id); if (city == null) { return(HttpNotFound()); } ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", city.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", city.ProvinceId); return(View(city)); }
public ActionResult Edit([Bind(Include = "UserId,UserName,FirstName,LastName,DateBirth,Phone,Address,Photo,PhotoFile,DepartamentId,ProvinceId,CityId,CompanyId")] User user, HttpPostedFileBase PhotoFile) { if (ModelState.IsValid) { //var folder = "~/Content/Users"; //var file = $"{user.UserId}.jpg"; if (user.PhotoFile != null) { var file = string.Format("{0}.jpg", user.UserId); var folder = "~/Content/Users"; //var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); var response = FilesHelper.UploadPhoto(PhotoFile, folder, file, user.Photo); user.Photo = string.Format("{0}/{1}", folder, file); } //if user change e-amail using (var db2 = new Ecommerce01Context()) { var currentUser = db2.Users.Find(user.UserId); if (currentUser.UserName != user.UserName) { UsersHelper.UpdateUserName(currentUser.UserName, user.UserName); } } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message + " NON RIESCO A SALVARE, email duplicata presente nel sistema"); //return View(user); //ModelState.AddModelError(string.Empty, ex.Message); } } ViewBag.CityId = new SelectList(DropDownHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(DropDownHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", user.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", user.ProvinceId); return(View(user)); }
public ActionResult Edit([Bind(Include = "CityId,Name,SigCap,DepartamentId,ProvinceId,Latitud,Longitud")] City city) { if (ModelState.IsValid) { //db.Entry(city).State = EntityState.Modified; //db.SaveChanges(); //return RedirectToAction("Index"); // var existingCitye = db.Cities.SingleOrDefault( c => c.Name == city.Name && c.SigCap == city.SigCap); if (existingCitye != null) { ModelState.AddModelError(string.Empty, "Esiste già un Registro con lo stesso valore"); } // else { //// db.Entry(city).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception exception) { //if (exception.InnerException?.InnerException != null && exception.InnerException.InnerException.Message.Contains("_Index")) //{ // ModelState.AddModelError(string.Empty, "Esiste gia un Registro con lo stesso valore"); //} //else //{ ModelState.AddModelError(string.Empty, exception.Message); //} } } } ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", city.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", city.ProvinceId); return(View(city)); }
public ActionResult Edit([Bind(Include = "ProvinceId,Name,SigCap,TwoInitial,Latitud,Longitud,DepartamentId")] Province province) { if (ModelState.IsValid) { //db.Entry(province).State = EntityState.Modified; //db.SaveChanges(); //return RedirectToAction("Index"); /// if (db.Provinces.Any(d => d.Name.Equals(province.Name))) { ModelState.AddModelError(string.Empty, "Esiste già un Registro con lo stesso valore"); } else { //// db.Entry(province).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception exception) { //if (exception.InnerException?.InnerException != null && exception.InnerException.InnerException.Message.Contains("_Index")) //{ // ModelState.AddModelError(string.Empty," 2 Esiste già un Registro con lo stesso valore"); //} //else //{ ModelState.AddModelError(string.Empty, exception.Message); //} return(View(province)); } } } ViewBag.DepartamentId = new SelectList( DropDownHelper.GetDepartaments(), "DepartamentId", "Name", province.DepartamentId); return(View(province)); }
// GET: Users/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = db.Users.Find(id); if (user == null) { return(HttpNotFound()); } ViewBag.CityId = new SelectList(DropDownHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(DropDownHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartamentId = new SelectList(DropDownHelper.GetDepartaments(), "DepartamentId", "Name", user.DepartamentId); ViewBag.ProvinceId = new SelectList(DropDownHelper.GetProvinces(), "ProvinceId", "Name", user.ProvinceId); return(View(user)); }
// GET: Provinces/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var province = db.Provinces.Find(id); if (province == null) { return(HttpNotFound()); } ViewBag.DepartamentId = new SelectList( DropDownHelper.GetDepartaments(), "DepartamentId", "" + "Name", province.DepartamentId); return(View(province)); }