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}.jpg", product.ProductID); var response = fileHelper.UploadPhoto(product.ImageFile, folder, file); if (response) { var 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(comboHelper.GetCategories(user.CompanyID), "CategoryID", "Description"); ViewBag.ImpuestoID = new SelectList(comboHelper.GetImpuestos(user.CompanyID), "ImpuestoID", "Description"); return(View(product)); }
/// <summary> /// /// </summary> /// <param name="shoppingCartModel"></param> /// <returns></returns> public ShoppingCartModel CreateShoppingCart(ShoppingCartModel shoppingCartModel) { var newShoppingCart = new ShoppingCart() { Id = shoppingCartModel.id, Date = DateTime.Now, ShoppingProducts = new List <ShoppingProduct>() }; _shoppingCartRepository.Add(newShoppingCart); _context.SaveChanges(); if (shoppingCartModel.shoppingProducts != null && shoppingCartModel.shoppingProducts.Count > 0) { foreach (var prod in shoppingCartModel.shoppingProducts) { newShoppingCart.ShoppingProducts.Add(CreateShoppingProduct(prod)); } } _context.SaveChanges(); return(ShoppingCartModelBuilder.Create(newShoppingCart)); }
public ActionResult Create([Bind(Include = "DepartamentsId,Name")] Departaments departaments) { if (ModelState.IsValid) { db.Departaments.Add(departaments); try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (System.Exception ex) { //tratamento de erros na hora de excluir departamentos if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Não é possivel Mover Inserir valores duplicados!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } return(View(departaments)); } } return(View(departaments)); }
public ActionResult Create(Department department) { if (ModelState.IsValid) { db.Departments.Add(department); 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, "Ya existe un regsitro con ese Nombre!!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(department)); } return(View(department)); }
public ActionResult Create(Company company) { db.Companies.Add(company); if (ModelState.IsValid) { db.Companies.Add(company); db.SaveChanges(); if (company.LogoFile != null) { var pic = string.Empty; var folder = "~/Content/Logos"; var file = string.Format("{0}.jpg", company.CompanyId); var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file); if (response) { pic = string.Format("{0}/{1}", folder, file); company.Logo = pic; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(), "CityId", "Name", company.CityId); ViewBag.DepartmentsId = new SelectList(CombosHelper.GetDepartments(), "DepartmentsId", "Name", company.DepartmentsId); return(View(company)); }
public ActionResult Create([Bind(Include = "DepartmentId,Name")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); 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, "There are record with the same value."); } else { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(department)); } return(View(department)); }
public ActionResult Create([Bind(Include = "DepartamentoId,Nome")] Departamento departamento) { if (ModelState.IsValid) { db.Departamentoes.Add(departamento); try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception Excecao) { if (Excecao.InnerException != null && Excecao.InnerException.InnerException != null && Excecao.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, " Não é possivel inserir dois departementos com o mesmo nome!"); } else { ModelState.AddModelError(string.Empty, Excecao.Message); } return(View(departamento)); } } return(View(departamento)); }
public IHttpActionResult PutCity(int id, City city) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != city.CityID) { return(BadRequest()); } db.Entry(city).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); //pa despues rodearlo con try catch OJO!! a validar registros duplicados y registros relacionados AL BORRAR!!! userHelper.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 = fileHelper.UploadPhoto(user.PhotoFile, folder, file); if (response) { var 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(comboHelper.GetCities(user.DepartmentID), "CityID", "Name"); ViewBag.CompanyID = new SelectList(comboHelper.GetCompanies(), "CompanyID", "Name"); ViewBag.DepartmentID = new SelectList(comboHelper.GetDepartments(), "DepartmentID", "Name"); return(View(user)); }
public ActionResult Create([Bind(Include = "DepartamentsId,Nome")] Departaments departaments) { if (ModelState.IsValid) { db.Departaments.Add(departaments); try { db.SaveChanges(); } catch (DbUpdateException ex) { if (ex.InnerException.InnerException.Message.Contains("Departament_Name_Index")) { ModelState.AddModelError(string.Empty, "Não é possível incluir mais de um departamento com o mesmo nome!"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.InnerException.Message); } return(View(departaments)); } return(RedirectToAction("Index")); } return(View(departaments)); }
public ActionResult Create(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, "Ya existe un regsitro con ese Nombre!!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(city)); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name"); return(View(city)); }
public ActionResult Create([Bind(Include = "CategoryId,Description,CompanyId")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (System.Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Não é possível inserir duas categorias com o mesmo nome se pertencerem a uma mesma distribuidora!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } } ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", category.CompanyId); return(View(category)); }
public IHttpActionResult PutDepartment(int id, Department department) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != department.DepartmentID) { return(BadRequest()); } db.Entry(department).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "DepartmentID,Name")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); 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, "no se puede crear otro departamento con el mismo nombre"); } else { ModelState.AddModelError(String.Empty, ex.Message); } return(View(department)); } } return(View(department)); }
public bool RegisterCustomer(CustomerRequestDto customerRequestDto) { if (UserExists(customerRequestDto.userRequestDto.Username)) { return(false); } byte[] passwordHash, passwordSalt; CreatePasswordHash(customerRequestDto.userRequestDto.Password, out passwordHash, out passwordSalt); var user = new User { UserId = Guid.NewGuid(), Username = customerRequestDto.userRequestDto.Username, PasswordHash = passwordHash, PasswordSalt = passwordSalt }; _ecommerceContext.Add(user); if (_ecommerceContext.SaveChanges() == 1) { if (_customerServiceManager.AddCustomer(user.UserId, customerRequestDto)) { if (_cartServiceManager.CreateCart(user.UserId)) { return(true); } } } return(false); }
public ActionResult Create([Bind(Include = "DepartamentsId,Name")] Departaments departaments) { if (ModelState.IsValid) { db.Departaments.Add(departaments); try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (System.Exception ex) { //Abaixo estou verificando se já existe o Departamento em questão! if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Esse Departamento já existe!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } return(View(departaments)); } } return(View(departaments)); }
public ActionResult Create([Bind(Include = "DepartamentsId,Name")] Departaments departaments) { if (ModelState.IsValid) { db.Departaments.Add(departaments); try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (System.Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { ModelState.AddModelError(string.Empty, "Já existe um Departamento com este nome."); } else { ModelState.AddModelError(string.Empty, ex.Message); } return(View(departaments)); } } return(View(departaments)); }
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 IActionResult Buy(int prodID) { System.Console.WriteLine("*************************************************"); System.Console.WriteLine(prodID); Product currentProduct = _context.Products.Single(i => i.ProductID == prodID); Customer currentCustomer = _context.Customers.Include(o => o.Orders).Single(c => c.CustomerID == HttpContext.Session.GetInt32("userID")); if (currentCustomer.Orders.Count < 1) { Order newOrder = new Order { TotalAmount = currentProduct.Price, Open = 1, CustomerID = currentCustomer.CustomerID }; Cart newCart = new Cart { OrderID = newOrder.OrderID, ProductID = prodID }; // _context.Orders.Add(newOrder); // _context.SaveChanges(); _context.Cart.Add(newCart); _context.SaveChanges(); } else { Order currentOrder = currentCustomer.Orders.Single(o => o.Open == 1); if (currentOrder != null) { Cart newCart = new Cart { OrderID = currentOrder.OrderID, ProductID = prodID }; currentOrder.TotalAmount = currentOrder.TotalAmount + currentProduct.Price; _context.Cart.Add(newCart); _context.SaveChanges(); } else { Order newOrder = new Order { TotalAmount = currentProduct.Price, Open = 1, CustomerID = currentCustomer.CustomerID }; Cart newCart = new Cart { OrderID = newOrder.OrderID, ProductID = prodID }; // _context.Orders.Add(newOrder); // _context.SaveChanges(); _context.Cart.Add(newCart); _context.SaveChanges(); } } return(RedirectToAction("Products")); }
public ActionResult Create([Bind(Include = "CompanhiaId,Nome,Telefone,Endereço,Logo")] Companhia companhia) { if (ModelState.IsValid) { db.Companhias.Add(companhia); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(companhia)); }
public ActionResult Create([Bind(Include = "DepartamentsID,Name")] Departaments departaments) { if (ModelState.IsValid) { db.Departaments.Add(departaments); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(departaments)); }
public ActionResult Criar([Bind(Include = "Id,Nome,Descricao")] Categoria categoria) { if (ModelState.IsValid) { db.Categorias.Add(categoria); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoria)); }
public ActionResult Create([Bind(Include = "StateId,Description")] State state) { if (ModelState.IsValid) { db.States.Add(state); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(state)); }
public ActionResult Create(Impuesto impuesto) { if (ModelState.IsValid) { db.Impuestoes.Add(impuesto); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(impuesto)); }
public static Response NewOrder(NewOrderView view, string userName) { using (var transaction = db.Database.BeginTransaction()) { try { var user = db.Users.Where(u => u.UserName == userName).FirstOrDefault(); var order = new Orders { CompanyId = user.CompanyId, CustomerId = view.CustomerId, Date = view.Date, Remarks = view.Remarks, StateId = DBHelper.GetState("Criado", db), }; db.Orders.Add(order); db.SaveChanges(); var details = db.OrderDetailTmp.Where(odt => odt.UserName == userName).ToList(); foreach (var detail in details) { var orderDetail = new OrderDetails { Description = detail.Description, OrderId = order.OrderId, Price = detail.Price, ProductId = detail.ProductId, Quantity = detail.Quantity, TaxRate = detail.TaxRate }; db.OrderDetail.Add(orderDetail); db.OrderDetailTmp.Remove(detail); } db.SaveChanges(); transaction.Commit(); return(new Response { Succeeded = true }); } catch (Exception ex) { transaction.Rollback(); return(new Response { Message = ex.Message, Succeeded = false }); throw; } } }
public ActionResult Criar([Bind(Include = "Id,Nome,Login,Senha,CPF,UsuarioTipo")] Usuario usuario) { if (ModelState.IsValid) { db.Usuarios.Add(usuario); db.SaveChanges(); return(RedirectToAction("Lista", "LoginAdm")); } return(View(usuario)); }
public ActionResult Edit(Warehouse warehouse) { if (ModelState.IsValid) { db.Entry(warehouse).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CityID = new SelectList(comboHelper.GetCities(warehouse.DepartmentID), "CityID", "Name"); ViewBag.DepartmentID = new SelectList(comboHelper.GetDepartments(), "DepartmentID", "Name"); return(View(warehouse)); }
public ActionResult Create([Bind(Include = "CityId,Name,DepartamentsId")] City city) { if (ModelState.IsValid) { db.Cities.Add(city); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartments(), "DepartamentsId", "Name"); return(View()); }
public ActionResult Create([Bind(Include = "TaxId,Description,Rate,CompanyId")] Tax tax) { if (ModelState.IsValid) { db.Taxes.Add(tax); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", tax.CompanyId); return(View(tax)); }
public static Response newOrder(NewOrderView view, string username) { using (var transaction = db.Database.BeginTransaction()) { try { var user = db.Users.Where(u => u.UserName == username).FirstOrDefault(); var order = new Order { CompanyID = user.CompanyID, CustomerID = view.CustomerID, Date = view.Date, Remarks = view.Remarks, StateID = dbHelper.GetState("Created", db), }; db.Orders.Add(order); db.SaveChanges(); var details = db.OrderDetailTemps.Where(o => o.UserName == username).ToList(); foreach (var detail in details) { var orderdetail = new OrderDetail { Description = detail.Description, OrderID = order.CompanyID, Price = detail.Price, ProductID = detail.ProductID, Quantity = detail.Quantity, ImpuestoRate = detail.ImpuestoRate }; db.OrderDetails.Add(orderdetail); db.OrderDetailTemps.Remove(detail); } db.SaveChanges(); transaction.Commit(); return(new Response { Succeded = true }); } catch (Exception ex) { transaction.Rollback(); return(new Response { Message = ex.Message, Succeded = false, }); } } }