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}-{1}.jpg", company.CompanyId, company.Name); var respose = FilesHelpers.UploadPhoto(company.LogoFile, folder, file); if (respose) { var pic = string.Format("{0}/{1}", folder, file); //si respose es true, actualizamos el logo de la compania company.Logo = pic; //actalizamos la dv db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", company.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", company.DepartmentId); return(View(company)); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { byte[] imagenActual = null; HttpPostedFileBase FileBase = Request.Files[0]; if (FileBase == null) { imagenActual = db.Users.SingleOrDefault(t => t.UserID == user.UserID).Foto; } else { WebImage image = new WebImage(FileBase.InputStream); user.Foto = image.GetBytes(); } db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityID = new SelectList(CombosHelpers.GetCities(user.DepartmentID), "CityID", "Name", user.CityID); ViewBag.CompanyID = new SelectList(CombosHelpers.GetCompanies(), "CompanyID", "Name", user.CompanyID); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", user.DepartmentID); return(View(user)); }
public ActionResult Create() { ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name"); ViewBag.CompanyId = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name"); return(View()); }
// GET: Companies/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CityID = new SelectList(CombosHelpers.GetCities(0), "CityID", "Name"); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name"); return(View()); }
public ActionResult Create() { //el viewBag sirve para conectar datos entre el controlador y la vista ViewBag.DepartmentId = new SelectList( CombosHelpers.GetDepartments() , "DepartmentId" , "Name"); return(View()); }
public ActionResult Edit(Warehouse warehouse) { if (ModelState.IsValid) { db.Entry(warehouse).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", warehouse.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", warehouse.DepartmentId); return(View(warehouse)); }
public ActionResult Create(Warehouse warehouse) { if (ModelState.IsValid) { db.Warehouses.Add(warehouse); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityID = new SelectList(CombosHelpers.GetCities(warehouse.DepartmentID), "CityID", "Name", warehouse.CityID); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", warehouse.DepartmentID); return(View(warehouse)); }
public ActionResult Create() { ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name"); var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); var customer = new Customer { CompanyId = user.CompanyId }; return(View(customer)); }
public ActionResult Edit(City city) { if (ModelState.IsValid) { dbContext.Entry(city).State = EntityState.Modified; dbContext.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList( CombosHelpers.GetDepartments() , "DepartmentId" , "Name" , city.DepartmentId); return(View(city)); }
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(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", customer.DepartmentId); return(View(customer)); } UsersHelper.CreateUserASP(customer.UserName, "Customer"); var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); var companyCustomer = new CompanyCustomers { 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(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); }
// GET: Companies/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Company company = db.Companies.Find(id); if (company == null) { return(HttpNotFound()); } ViewBag.CityID = new SelectList(CombosHelpers.GetCities(company.DepartmentID), "CityID", "Name", company.CityID); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", company.DepartmentID); return(View(company)); }
public ActionResult Create(Company company) { if (ModelState.IsValid) { HttpPostedFileBase FileBase = Request.Files[0]; WebImage image = new WebImage(FileBase.InputStream); company.Logo = image.GetBytes(); db.Companies.Add(company); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityID = new SelectList(CombosHelpers.GetCities(company.DepartmentID), "CityID", "Name", company.CityID); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", company.DepartmentID); return(View(company)); }
// GET: Customers/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Customer customer = db.Customers.Find(id); if (customer == null) { return(HttpNotFound()); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", customer.DepartmentId); return(View(customer)); }
// 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(CombosHelpers.GetCities(warehouse.DepartmentID), "CityID", "Name", warehouse.CityID); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", warehouse.DepartmentID); return(View(warehouse)); }
public ActionResult Edit(Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(customer.DepartmentId), "CityID", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", customer.DepartmentId); return(View(customer)); }
public ActionResult Create(Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); //El customer tiene rol de Customer UsersHelper.CreateUserASP(customer.UserName, "Customer"); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); }
public ActionResult Edit(Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); // TODO: validar cuando el email cambia return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { HttpPostedFileBase FileBase = Request.Files[0]; WebImage image = new WebImage(FileBase.InputStream); user.Foto = image.GetBytes(); db.Users.Add(user); db.SaveChanges(); UsersHelper.CreateUserASP(user.UserName, "User"); return(RedirectToAction("Index")); } ViewBag.CityID = new SelectList(CombosHelpers.GetCities(user.DepartmentID), "CityID", "Name", user.CityID); ViewBag.CompanyID = new SelectList(CombosHelpers.GetCompanies(), "CompanyID", "Name", user.CompanyID); ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", user.DepartmentID); return(View(user)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } City city = dbContext.Cities.Find(id); if (city == null) { return(HttpNotFound()); } ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments() , "DepartmentId" , "Name" , city.DepartmentId); return(View(city)); }
public ActionResult Create() { ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name"); ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name"); var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } var warehouse = new Warehouse { CompanyId = user.CompanyId }; return(View(warehouse)); }
public ActionResult Create(City city) { if (ModelState.IsValid) { dbContext.Cities.Add(city); try { dbContext.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) //si aparece"_Index" estamos duplicando un valor { ModelState.AddModelError(string.Empty, "There are a record with the same value"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } return(RedirectToAction("Index")); } //OrderBy(x=> x.Name) ordeno el dropDownList por nombre ViewBag.DepartmentId = new SelectList( CombosHelpers.GetDepartments() , "DepartmentId" , "Name" , city.DepartmentId); return(View(city)); }