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(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 void Update(Feature feature) { var img = db.Feature.First(x => x.Id == feature.Id); db.Entry(img).CurrentValues.SetValues(feature); db.SaveChanges(); }
public ActionResult AddProduct(AddProductView view) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); 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")); } ViewBag.ProductId = new SelectList(CombosHelper.GetProducts(user.CompanyId), "ProductId", "Description"); return(PartialView()); }
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 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)); }
public Category GetById(int Id) { var category = _context.Categories.Single(cat => cat.Id == Id); _context.Entry(category).Collection(x => x.SubCategories).Load(); return(category); }
public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
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.Succeded) { ModelState.AddModelError(string.Empty, response.Message); transaction.Rollback(); } userHelper.CreateUserASP(customer.UserName, "Customer"); var user = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); var companyuser = new CompanyCustomer { CompanyID = user.CompanyID, CustomerID = customer.CustomerID }; db.CompanyCustomers.Add(companyuser); db.SaveChanges(); transaction.Commit(); if (customer.PhotoFile != null) { //var pic = string.Empty; var folder = "~/Content/Customers"; var file = string.Format("{0}.jpg", customer.CustomerID); var respo = fileHelper.UploadPhoto(customer.PhotoFile, folder, file); if (respo) { var pic = string.Format("{0}/{1}", folder, file); customer.Photo = pic; db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); ModelState.AddModelError(string.Empty, ex.Message); } } } ViewBag.CityID = new SelectList(comboHelper.GetCities(customer.DepartmentID), "CityID", "Name"); ViewBag.DepartmentID = new SelectList(comboHelper.GetDepartments(), "DepartmentID", "Name"); return(View(customer)); }
public async Task <IActionResult> PutCategory(int id, [FromForm] Category category) { if (id != category.CatId) { return(BadRequest()); } category = await UploadImage(category); _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(City city) { if (ModelState.IsValid) { db.Entry(city).State = EntityState.Modified; 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 async Task <IActionResult> PutProductGroup(int id, ProductGroup productGroup) { if (id != productGroup.GroupId) { return(BadRequest()); } _context.Entry(productGroup).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductGroupExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutLog(int id, Log log) { if (id != log.LogId) { return(BadRequest()); } _context.Entry(log).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWishList(int id, WishList wishList) { if (id != wishList.WishListId) { return(BadRequest()); } _context.Entry(wishList).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WishListExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProductInventoryHistory([FromRoute] int id, [FromBody] ProductInventoryHistory productInventoryHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productInventoryHistory.ProductInventoryHistoryId) { return(BadRequest()); } _context.Entry(productInventoryHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductInventoryHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUsuario(int id, Usuario usuario) { if (id != usuario.ID) { return(BadRequest()); } _context.Entry(usuario).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsuarioExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutClientPosSetting([FromRoute] int id, [FromBody] ClientPosSettings clientPosSettings) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != clientPosSettings.Id) { return(BadRequest()); } _context.Entry(clientPosSettings).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientPosSettingsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutLocation([FromRoute] int id, [FromBody] Location location) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != location.LocationId) { return(BadRequest()); } _context.Entry(location).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "DepartamentsId,Nome")] Departaments departaments) { if (ModelState.IsValid) { db.Entry(departaments).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateException ex) { if (ex.InnerException.InnerException.Message.Contains("Departament_Name_Index")) { ModelState.AddModelError(string.Empty, "Não será possível alterar o nome do departamento para um nome que já exista!"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } return(View(departaments)); } return(View(departaments)); }
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 Edit([Bind(Include = "DepartmentID,Name")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; 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)); throw; } } return(View(department)); }
public async Task <IActionResult> PutCompra(int id, Compra compra) { if (id != compra.ID) { return(BadRequest()); } _context.Entry(compra).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompraExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
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 async Task <IActionResult> PutProducts(int id, [FromForm] Products products) { if (id != products.ProductId) { return(BadRequest()); } products = await UploadImage(products); _context.Entry(products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "DepartmentId,Name")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; 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)); }
public async Task <IActionResult> PutProductType([FromRoute] int id, [FromBody] ProductType productType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productType.ProductTypeId) { return(BadRequest()); } productType.ModifiedDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Pacific Standard Time"); _context.Entry(productType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "DepartamentsId,Name")] Departaments departaments) { if (ModelState.IsValid) { db.Entry(departaments).State = EntityState.Modified; 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 Edit([Bind(Include = "DepartamentoId,Nome")] Departamento departamento) { if (ModelState.IsValid) { db.Entry(departamento).State = EntityState.Modified; 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 ActionResult Edit(Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; 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 registro con ese Nombre!!"); } else { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(department)); } return(View(department)); }
public async Task <IActionResult> PutCustomers(int id, Customers customers) { if (id != customers.CustomerId) { return(BadRequest()); } _context.Entry(customers).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }