public IHttpActionResult PutUser(int id, User user) { db.Configuration.ProxyCreationEnabled = false; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.UserId) { return(BadRequest()); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); var responsse = DBHelper.SaveChanges(db); if (responsse.Succeded) { UsersHelper.CreateUserASP(user.UserName, "User"); } else { ModelState.AddModelError(string.Empty, responsse.Message); return(View(user)); } if (user.PhotoFile != null) { var pic = string.Empty; var folder = "~/Content/Users"; pic = FilesHelper.GetNamePhoto(user.UserId); if (pic != null) { var response = FilesHelper.UploadPhoto(user.PhotoFile, pic, folder); user.Photo = string.Format("{0}/{1}", folder, pic); db.Entry(user).State = EntityState.Modified; var respons = DBHelper.SaveChanges(db); if (!respons.Succeded) { ModelState.AddModelError(string.Empty, respons.Message); return(View(user)); } } } 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.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
public ActionResult Create( Company company) { if (ModelState.IsValid) { db.Companies.Add(company); var respons = DBHelper.SaveChanges(db); if (!respons.Succeded) { ModelState.AddModelError(string.Empty, respons.Message); return View(company); } if (company.LogoFile != null) { var folder = "~/Content/Logos"; var pic = FilesHelper.GetNamePhoto(company.CompanyId); if (pic != null) { pic = FilesHelper.UploadPhoto(company.LogoFile, pic, folder); company.Logo = string.Format("{0}/{1}", folder, pic); db.Entry(company).State = EntityState.Modified; var respon = DBHelper.SaveChanges(db); if (!respon.Succeded) { ModelState.AddModelError(string.Empty, respon.Message); return View(company); } } } return RedirectToAction("Index"); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", company.DepartmentId); return View(company); }
public ActionResult Create(Product product) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { db.Products.Add(product); var responsse = DBHelper.SaveChanges(db); if (!responsse.Succeded) { ModelState.AddModelError(string.Empty, responsse.Message); return(View(product)); } if (product.ImageFile != null) { var pic = string.Empty; var folder = "~/Content/Products"; pic = FilesHelper.GetNamePhoto(product.ProductId); if (pic != null) { var response = FilesHelper.UploadPhoto(product.ImageFile, pic, folder); product.Image = string.Format("{0}/{1}", folder, pic); db.Entry(product).State = EntityState.Modified; var respons = DBHelper.SaveChanges(db); if (!responsse.Succeded) { ModelState.AddModelError(string.Empty, responsse.Message); return(View(product)); } } } return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId); ViewBag.TaxId = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId); return(View(product)); }
public ActionResult Edit([Bind(Include = "StateId,Description")] State state) { if (ModelState.IsValid) { db.Entry(state).State = EntityState.Modified; var respon = DBHelper.SaveChanges(db); if (!respon.Succeded) { ModelState.AddModelError(string.Empty, respon.Message); return(View(state)); } return(RedirectToAction("Index")); } return(View(state)); }
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(view)); }
public ActionResult Edit(Warehouse warehouse) { if (ModelState.IsValid) { db.Entry(warehouse).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", warehouse.DepartmentId); return(View(warehouse)); }
public ActionResult Edit([Bind(Include = "DepartmentId,Name")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; var respon = DBHelper.SaveChanges(db); if (!respon.Succeded) { ModelState.AddModelError(string.Empty, respon.Message); return(View(department)); } return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Edit(Tax tax) { if (ModelState.IsValid) { db.Entry(tax).State = EntityState.Modified; var respon = DBHelper.SaveChanges(db); if (!respon.Succeded) { ModelState.AddModelError(string.Empty, respon.Message); return(View(tax)); } return(RedirectToAction("Index")); } return(View(tax)); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; var respon = DBHelper.SaveChanges(db); if (!respon.Succeded) { ModelState.AddModelError(string.Empty, respon.Message); ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", category.CompanyId); return(View(category)); } return(RedirectToAction("Index")); } ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", category.CompanyId); return(View(category)); }
public ActionResult Edit(Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (!response.Succeded) { ModelState.AddModelError(string.Empty, response.Message); return(View()); } //TODO: Validate when the customer email change return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); return(View(customer)); }
public ActionResult Edit([Bind(Include = "CityId,Name,DepartmentId")] City city) { if (ModelState.IsValid) { db.Entry(city).State = EntityState.Modified; var respons = DBHelper.SaveChanges(db); if (!respons.Succeded) { ModelState.AddModelError(string.Empty, respons.Message); return(View(city)); } return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", city.DepartmentId); return(View(city)); }