public ActionResult Create(Company company) { if (ModelState.IsValid) { db.Companies.Add(company); db.SaveChanges(); if (company.CompanyPhotoFile != null) { var folder = "~/Content/Golo"; var response = FilHelper.UploadPhoto(company.CompanyPhotoFile, folder, string.Format("{0}.jpg", company.CompanyId)); if (response) { var pic = string.Format("{0}/{1}.jpg", folder, company.CompanyId); company.CompanyPhoto = pic; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(ComboHelper.getCities(), "CityId", "CitiesName", company.CityId); ViewBag.DepartmentId = new SelectList(ComboHelper.getDepartment(), "DepartmentId", "DepartmentName", company.DepartmentId); return(View(company)); }
public ActionResult Edit([Bind(Include = "CityId,CitiesName,DepartmentId")] City city) { if (ModelState.IsValid) { db.Entry(city).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(ComboHelper.getDepartment(), "DepartmentId", "DepartmentName", city.DepartmentId); return(View(city)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { try { db.Users.Add(user); db.SaveChanges(); UsersHelper.CreateUserASP(user.UserName, "User"); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.Message.Contains("Index")) { ModelState.AddModelError(string.Empty, "La casilla {0} ya existe en la tabla"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } if (user.UserPhotoFile != null) { var folder = "~/Content/StatePho"; var response = FilHelper.UploadPhoto(user.UserPhotoFile, folder, string.Format("{0}.jpg", user.UserId)); if (response) { var pic = string.Format("{0}/{1}.jpg", folder, user.UserId); user.UserPhoto = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(ComboHelper.getCities(), "CityId", "CitiesName", user.CityId); ViewBag.CompanyId = new SelectList(ComboHelper.getCompanies(), "CompanyId", "CompanyName", user.CompanyId); ViewBag.DepartmentId = new SelectList(ComboHelper.getDepartment(), "DepartmentId", "DepartmentName", user.DepartmentId); return(View(user)); }
public ActionResult Edit([Bind(Include = "DepartmentId,DepartmentName")] DepartmentModel departmentModel) { if (ModelState.IsValid) { db.Entry(departmentModel).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.Message.Contains("Index")) { ModelState.AddModelError(string.Empty, "La casilla {0} ya existe en la tabla"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } } return(View(departmentModel)); }