public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); UsersHelper.CreateUserASP(user.UserName, "User"); if (user.PhotoFile != null) { var pic = string.Empty; var folder = "~/Content/Users"; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartments(), "DepartamentsId", "Name", user.DepartamentsId); return(View(user)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { if (user.PhotoFile != null) { var pic = string.Empty; var folder = "~/Content/Users"; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { pic = string.Format("{0}/{1}", folder, file); user.Photo = pic; } } var db2 = new EcommerceContext(); var currentUser = db2.Users.Find(user.UserId); if (currentUser.UserName != user.UserName) { UsersHelper.UpdateUserName(currentUser.UserName, user.UserName); } db2.Dispose(); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartments(), "DepartamentsId", "Name", user.DepartamentsId); return(View(user)); }
// GET: Users/Create public ActionResult Create() { ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name"); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name"); ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartments(), "DepartamentsId", "Name"); return(View()); }
// GET: Users/Create public ActionResult Create() { //precisa trocar o db.Cities pelo metodo criado no CombosHelper pra chamar a lista oredenada ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name"); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name"); ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name"); return(View()); }
// GET: Users/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } User user = db.Users.Find(id); if (user == null) { return(HttpNotFound()); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartments(), "DepartamentsId", "Name", user.DepartamentsId); return(View(user)); }