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(User user) { if (ModelState.IsValid) { var folder = "~/Content/Golo"; var pic = string.Empty; if (user.UserPhotoFile != null) { var response = FilHelper.UploadPhoto(user.UserPhotoFile, folder, string.Format("{0}.jpg", user.UserId)); if (response) { pic = string.Format("{0}/{1}.jpg", folder, user.UserId); user.UserPhoto = pic; } } var db2 = new DBPrintumContext(); 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(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 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)); }