public async Task <IHttpActionResult> PutBuySlip(int id, BuySlip buySlip) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != buySlip.Id) { return(BadRequest()); } db.Entry(buySlip).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BuySlipExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetBuySlip(int id) { BuySlip buySlip = await db.BuySlips.Include(s => s.BuySlipItems) .Where(xs => xs.Id == id).SingleAsync(); if (buySlip == null) { return(NotFound()); } return(Ok(buySlip)); }
public async Task <IHttpActionResult> PostBuySlip(BuySlip buySlip) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BuySlips.Add(buySlip); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = buySlip.Id }, buySlip)); }
public ActionResult Create([Bind(Include = "Id,DateCreation,Description,DeliveryMan,SupplierId,PeriodId,AppUserId")] BuySlip buySlip) { if (ModelState.IsValid) { db.BuySlips.Add(buySlip); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PeriodId = new SelectList(db.Periods, "Id", "Name", buySlip.PeriodId); ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Address", buySlip.SupplierId); return(View(buySlip)); }
// GET: BuySlips/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BuySlip buySlip = db.BuySlips.Find(id); if (buySlip == null) { return(HttpNotFound()); } return(PartialView(viewName: "Details", model: buySlip)); }
public async Task <IHttpActionResult> DeleteBuySlip(int id) { BuySlip buySlip = await db.BuySlips.FindAsync(id); if (buySlip == null) { return(NotFound()); } db.BuySlips.Remove(buySlip); await db.SaveChangesAsync(); return(Ok(buySlip)); }
public ActionResult DeleteConfirmed(int id) { BuySlip buySlip = db.BuySlips.Find(id); bool chkSlip = db.BuySlipItems.Where(x => x.BuySlipId == id).Any(); if (chkSlip) { TempData["message"] = "ابتدا اقلام مربوطه را حذف کنید"; TempData["success"] = "false"; return(Json(new { success = true })); } db.BuySlips.Remove(buySlip); db.SaveChanges(); TempData["message"] = "درخواست شما انجام شد"; TempData["success"] = "true"; return(Json(new { success = true })); }
public ActionResult Edit([Bind(Include = "Id,DateCreation,Description,DeliveryMan,SupplierId,EntrySlipTypeId,AppUserId")] BuySlip buySlip) { if (ModelState.IsValid) { db.Entry(buySlip).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = "درخواست شما انجام شد"; TempData["success"] = "true"; Session["BuySlipId"] = null; return(RedirectToAction("Index")); } ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Name", buySlip.SupplierId); TempData["message"] = "درخواست شما لغو شد"; TempData["success"] = "false"; return(View(buySlip)); }
public ActionResult BuySlipReport(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BuySlip buySlip = db.BuySlips.Find(id); if (buySlip == null) { TempData["message"] = "ویرایش انجام شد"; TempData["success"] = "false"; return(RedirectToAction(actionName: "Index", controllerName: "BuySlips")); } BuySlipViewModel bsViewModel = new BuySlipViewModel() { TotalPrice = db.BuySlipItems.Where(x => x.BuySlipId == id).Sum(x => x.Price * x.Quantity), Id = buySlip.Id, DateCreation = buySlip.DateCreation, DeliveryMan = buySlip.DeliveryMan, Description = buySlip.Description, EntrySlipType = buySlip.EntrySlipType.Name, Supplier = buySlip.Supplier.FirstName + " " + buySlip.Supplier.LastName, UserName = buySlip.ApplicationUser.UserName, AboutFotter = db.Abouts.FirstOrDefault(), BuySlipItems = db.BuySlipItems.Where(x => x.BuySlipId == id) .Select(x => new BuySlipItemViewModel() { Description = x.Description, Price = x.Price, Id = x.Id, ProductName = x.Product.Name, PriceInQuantity = x.Price * x.Quantity, Quantity = x.Quantity }).ToList() }; if (buySlip == null) { return(HttpNotFound()); } ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "LastName", buySlip.SupplierId); Session["BuySlipId"] = id; return(View(bsViewModel)); }
private void GetBuySlipId() { PersianCalendar pc = new PersianCalendar(); if (Session["BuySlipId"] == null) { BuySlip buyslip = new BuySlip(); buyslip.DateCreation = string.Format("{0}/{1}/{2}", pc.GetYear(DateTime.Now), pc.GetMonth(DateTime.Now), pc.GetDayOfMonth(DateTime.Now)); buyslip.AppUserId = User.Identity.GetUserId <int>(); db.BuySlips.Add(buyslip); db.SaveChanges(); Session["BuySlipId"] = buyslip.Id; } }
// GET: BuySlips/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BuySlip buySlip = db.BuySlips.Find(id); BuySlipViewModel bsViewModel = new BuySlipViewModel() { Id = buySlip.Id, DateCreation = buySlip.DateCreation, DeliveryMan = buySlip.DeliveryMan, Description = buySlip.Description, EntrySlipTypeId = buySlip.EntrySlipTypeId, SupplierId = buySlip.SupplierId, AppUserId = buySlip.AppUserId, TotalPrice = db.BuySlipItems.Where(x => x.BuySlipId == id).Sum(x => x.Price * x.Quantity), BuySlipItems = db.BuySlipItems.Where(x => x.BuySlipId == id) .Select(x => new BuySlipItemViewModel() { Description = x.Description, Price = x.Price, Id = x.Id, ProductName = x.Product.Name, PriceInQuantity = x.Price * x.Quantity, Quantity = x.Quantity }).ToList() }; if (buySlip == null) { return(HttpNotFound()); } ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "LastName", buySlip.SupplierId); ViewBag.EntrySlipTypeId = new SelectList(db.EntrySlipTypes, "Id", "Name", buySlip.EntrySlipTypeId); Session["BuySlipId"] = id; return(View(bsViewModel)); }