public ActionResult AddProduct() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.ProductId = new SelectList(CombosHelpers.GetProducts(user.CompanyID, false), "ProductId", "Description"); return(PartialView()); }
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 AddProduct(AddProductView view) { if (ModelState.IsValid) { var orderDetailTmp = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name && odt.ProductId == view.ProductId).FirstOrDefault(); if (orderDetailTmp == null) { var product = db.Products.Find(view.ProductId); orderDetailTmp = new OrderDetailTmp { Description = product.Description, Price = product.Price, ProductId = product.ProductID, Quantity = view.Quantity, TaxRate = product.Tax.Rate, UserName = User.Identity.Name, }; db.OrderDetailTmps.Add(orderDetailTmp); } else { orderDetailTmp.Quantity += view.Quantity; db.Entry(orderDetailTmp).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Create")); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.ProductId = new SelectList(CombosHelpers.GetProducts(user.CompanyID), "ProductId", "Description"); return(PartialView(view)); }
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}-{1}.jpg", user.UserId, user.FullName); var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file); if (respose) { var pic = string.Format("{0}/{1}", folder, file); //si respose es true, actualizamos el logo de la compania user.Photo = pic; //actalizamos la dv db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
public ActionResult Create(Product product) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); if (product.ImageFile != null) { var folder = "~/Content/Products"; var file = string.Format("{0}-{1}.jpg", product.ProductId, product.Description); var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file); if (respose) { var pic = string.Format("{0}/{1}", folder, file); //si respose es true, actualizamos el logo de la compania product.Image = pic; //actalizamos la dv db.Entry(product).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId); return(View(product)); }
public ActionResult Edit(Product product) { if (ModelState.IsValid) { if (product.ImageFile != null) { var pic = string.Empty; var folder = "~/Content/Products"; var file = string.Format("{0}-{1}.jpg", product.ProductId, product.Description); var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file); if (respose) { pic = string.Format("{0}/{1}", folder, file); product.Image = pic; } } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId); return(View(product)); }
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()); }
public ActionResult Edit(Product product) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); byte[] imagenActual = null; HttpPostedFileBase FileBase = Request.Files[0]; if (FileBase == null) { imagenActual = db.Products.SingleOrDefault(t => t.ProductID == product.ProductID).Image; } else { WebImage image = new WebImage(FileBase.InputStream); product.Image = image.GetBytes(); } if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CategoryID = new SelectList(CombosHelpers.GetCategories(product.CompanyID), "CategoryID", "Descripcion", product.CategoryID); ViewBag.TaxID = new SelectList(CombosHelpers.GetTaxes(product.CompanyID), "TaxID", "Description", product.TaxID); return(View(product)); }
public ActionResult AddProduct(AddProductView addProductView) { if (ModelState.IsValid) { var product = db.Products.Find(addProductView.ProductId); var orderDetailTmp = new OrderDetailTmp { Description = product.Description, Price = product.Price, ProductId = product.ProductId, Quantity = addProductView.Quantity, TaxRate = product.Tax.Rate, UserName = User.Identity.Name }; db.OrderDetailTmps.Add(orderDetailTmp); db.SaveChanges(); return(RedirectToAction("Create")); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.ProductId = new SelectList(CombosHelpers.GetProducts(user.CompanyId), "ProductId", "Description"); 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 Edit([Bind(Include = "id,Alumno_id,Curso_id,Nota")] AlumnoCurso alumnoCurso) { if (ModelState.IsValid) { db.Entry(alumnoCurso).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Alumno_id = new SelectList(CombosHelpers.GetAlumnos(), "id", "Nombre", alumnoCurso.Alumno_id); ViewBag.Curso_id = new SelectList(CombosHelpers.GetCursos(), "id", "Nombre", alumnoCurso.Curso_id); return(View(alumnoCurso)); }
public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(user.CompanyId), "CategoryId", "Description"); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(user.CompanyId), "TaxId", "Description"); var product = new Product { CompanyId = user.CompanyId }; return(View(product)); }
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 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)); }
// GET: Orders/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelpers.GetCustomers(user.CompanyID), "CustomerId", "FullName"); var view = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(), }; return(View(view)); }
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(Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelpers.GetCustomers(user.CompanyId), "CustomerId", "FullName"); return(View(order)); }
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: AlumnoCursoes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AlumnoCurso alumnoCurso = db.AlumnoCurso.Find(id); if (alumnoCurso == null) { return(HttpNotFound()); } ViewBag.Alumno_id = new SelectList(CombosHelpers.GetAlumnos(), "id", "Nombre", alumnoCurso.Alumno_id); ViewBag.Curso_id = new SelectList(CombosHelpers.GetCursos(), "id", "Nombre", alumnoCurso.Curso_id); return(View(alumnoCurso)); }
// 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: Products/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } ViewBag.CategoryID = new SelectList(CombosHelpers.GetCategories(user.CompanyID), "CategoryID", "Descripcion"); ViewBag.TaxID = new SelectList(CombosHelpers.GetTaxes(user.CompanyID), "TaxID", "Description"); var product = new Product { CompanyID = user.CompanyID, }; return(View(product)); }
// 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 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(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)); }