public ActionResult Edit(Customer customer) { if (ModelState.IsValid) { var db2 = new KissiContext(); var currentUser = db2.Customers.Find(customer.CustomerId); if (currentUser.UserName != customer.UserName) { UsersHelper.UpdateUserName(currentUser.UserName, customer.UserName); } db2.Dispose(); db.Entry(customer).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { //UsersHelper.CreateUserASP(customer.UserName, "Customer"); return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); //return RedirectToAction("Index"); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId); //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", customer.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); }
// GET: Users/Create public ActionResult Create() { ViewBag.CityId = new SelectList(CombosHelper.GetCities(0), "CityId", "Name"); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name"); return(View()); }
public ActionResult Create(Company company) { if (ModelState.IsValid) { db.Companies.Add(company); db.SaveChanges(); if (company.LogoFile != null) { var folder = "~/Content/Logos"; var file = string.Format("{0}.jpg", company.CompanyId); var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}.jpg", folder, company.CompanyId); company.Logo = pic; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", company.DepartmentId); return(View(company)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); UsersHelper.CreateUserASP(user.UserName, "User"); if (user.PhotoFile != null) { var folder = "~/Content/Users"; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}.jpg", folder, user.UserId); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
public ActionResult Create([Bind(Include = "CityId,Name,DepartmentId")] City city) { if (ModelState.IsValid) { db.Cities.Add(city); 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, "The are record we the same name in department"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", city.DepartmentId); return(View(city)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { if (user.PhotoFile != null) { var folder = "~/Content/Users"; var pic = string.Empty; var file = string.Format("{0}.jpg", user.UserId); var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { pic = string.Format("{0}/{1}.jpg", folder, file); user.Photo = pic; } } var db2 = new KissiContext(); 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(user.DepartmentId), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
public ActionResult Create(Customer customer) { if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { db.Customers.Add(customer); var response = DBHelper.SaveChanges(db); if (!response.Succeeded) { ModelState.AddModelError(string.Empty, response.Message); transaction.Rollback(); ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); } UserHelper.CreateUserASP(customer.UserName, "Customer"); var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); var companyCustomer = new CompanyCustomer { CompanyId = user.CompanyId, CustomerId = customer.CustomerId }; db.CompanyCustomers.Add(companyCustomer); db.SaveChanges(); transaction.Commit(); return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); ModelState.AddModelError(string.Empty, ex.Message); } } } ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); }
public ActionResult Create(Company company) { if (ModelState.IsValid) { db.Companies.Add(company); try { db.SaveChanges(); if (company.LogoFile != null) { var picture = string.Empty; var folder = "~/Content/Logos"; var response = FileHelper.UploadPhoto(company.LogoFile, folder, $"{company.CompanyId}.jpg"); if (response) { picture = $"{folder}/{company.CompanyId}.jpg"; company.Logo = picture; //actualizo la db: 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, "There are a record with the same Value."); } else { ModelState.AddModelError(string.Empty, ex.Message); } } } ViewBag.CityId = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", company.DepartmentId); return(View(company)); }
// GET: Customers/Create public ActionResult Create() { var user = db.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } //var customer = new Customer { CompanyId = user.CompanyId, }; ViewBag.CityId = new SelectList(CombosHelper.GetCities(0), "CityId", "Name"); //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name"); return(View()); }
// GET: Customers/Create public ActionResult Create() { //var user = db.Users.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault(); //var customer = new Customer //{ // CompanyId = user.CompanyId //}; ViewBag.CityId = new SelectList(CombosHelper.GetCities(0), "CityId", "Name"); //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name"); return(View()); }
public ActionResult Edit([Bind(Include = "UserId,UserName,FirstName,LastName,Phone,Address,Photo,DepartmentId,CompanyId,CityId")] User user) { if (ModelState.IsValid) { if (user.PhotoFile != null) { var picture = string.Empty; var folder = "~/Content/Users"; var response = FileHelper.UploadPhoto(user.PhotoFile, folder, $"{user.UserId}.jpg"); if (response) { picture = $"{folder}/{user.UserId}.jpg"; user.Photo = picture; } } //Busco el userName viejo a actualizar: var db2 = new ECommerceContext(); var currentUser = db2.Users.Find(user.UserId); if (currentUser.UserName != user.UserName) { UserHelper.UpdateUserName(currentUser.UserName, user.UserName); } //close de DB: db2.Dispose(); db.Entry(user).State = EntityState.Modified; try { //actualizo la db: db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { throw; } } ViewBag.CityId = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
// 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.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", city.DepartmentId); return(View(city)); }
// GET: WareHouses/Create public ActionResult Create() { var user = db.Users.Where(w => w.UserName.Equals(User.Identity.Name)).FirstOrDefault(); var werehouse = new WareHouse { CompanyId = user.CompanyId }; ViewBag.CityId = new SelectList(CombosHelper.GetCities(0), "CityId", "Name"); //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name"); return(View(werehouse)); }
public ActionResult Edit(Warehouse warehouse) { if (ModelState.IsValid) { db.Entry(warehouse).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId); //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", warehouse.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", warehouse.DepartmentId); return(View(warehouse)); }
// 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(user.DepartmentId), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
// GET: Warehouses/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Warehouse warehouse = db.Warehouses.Find(id); if (warehouse == null) { return(HttpNotFound()); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId); //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", warehouse.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", warehouse.DepartmentId); return(View(warehouse)); }
// GET: Cities/Create public ActionResult Create() { ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name"); return(View()); }