public JsonResponse Change(PurchaseRequestLineitem purchaseRequestLineitem)
        {
            purchaseRequestLineitem.Product = null;
            if (purchaseRequestLineitem == null)
            {
                return new JsonResponse {
                           Code = -100, Message = $"purchaseRequestLineitem cannot be null"
                }
            }
            ;
            if (!ModelState.IsValid)
            {
                return new JsonResponse {
                           Code = -200, Message = $"ModelState is invalid", Error = ModelState
                }
            }
            ;
            db.PurchaseRequestLineitems.Attach(purchaseRequestLineitem);
            db.Entry(purchaseRequestLineitem).State = System.Data.Entity.EntityState.Modified;
            var recsAffected = db.SaveChanges();

            RecalcLineItemTotal(purchaseRequestLineitem.PurchaseRequestId);

            return(new JsonResponse {
                Message = "PurchaseRequestLineitem change successful!", Data = purchaseRequestLineitem
            });
        }
Ejemplo n.º 2
0
        // POST: PurchaseRequestLineitems/Change
        public ActionResult Change([FromBody] PurchaseRequestLineitem purchaseRequestLineitem)
        {
            if (!ModelState.IsValid || purchaseRequestLineitem.Quantity == 0)
            {
                var errorMessages = ModelStateErrors.GetModelStateErrors(ModelState);
                return(new JsonNetResult {
                    Data = new Msg {
                        Result = "Failed", Message = "ModelState invalid.", Data = errorMessages
                    }
                });
            }
            var purchaseRequest2 = db.PurchaseRequestLineitems.Find(purchaseRequestLineitem.Id);

            purchaseRequest2.Copy(purchaseRequestLineitem);
            try {
                db.SaveChanges();
                CalculatePurchaseRequestTotal(purchaseRequestLineitem.PurchaseRequestId);
            } catch (Exception ex) {
                return(new JsonNetResult {
                    Data = new Msg {
                        Result = "Failed", Message = ex.Message
                    }
                });
            }
            return(new JsonNetResult {
                Data = new Msg {
                    Result = "Success", Message = "Changed."
                }
            });
        }
        public JsonResponse Create(PurchaseRequestLineitem purchaseRequestLineitem)
        {
            if (purchaseRequestLineitem == null)
            {
                return new JsonResponse {
                           Code = -100, Message = $"purchaseRequestLineitem cannot be null"
                }
            }
            ;
            if (!ModelState.IsValid)
            {
                return new JsonResponse {
                           Code = -200, Message = $"ModelState is invalid", Error = ModelState
                }
            }
            ;
            db.PurchaseRequestLineitems.Add(purchaseRequestLineitem);
            var recsAffected = db.SaveChanges();

            RecalcLineItemTotal(purchaseRequestLineitem.PurchaseRequestId);

            return(new JsonResponse {
                Message = "PurchaseRequestLineitem create successful!", Data = purchaseRequestLineitem
            });
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            PurchaseRequestLineitem purchaseRequestLineitem = db.PurchaseRequestLineitems.Find(id);

            db.PurchaseRequestLineitems.Remove(purchaseRequestLineitem);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        static void run()
        {
            //var pEchoDot = new Product {
            //	Name = "Echo Dot",
            //	PartNumber = "EDOT",
            //	Price = 39.99,
            //	Unit = "Each",
            //	PhotoPath = null,
            //	VendorId = 1,
            //	Vendor = null
            //};
            //db.Products.Add(pEchoDot);
            //db.SaveChanges();

            var products   = db.Products.ToList();
            var product    = products[0];
            var vendorName = product.Vendor.Name;

            List <User> users  = db.Users.ToList();
            User        user   = db.Users.Find(1);
            User        nouser = db.Users.Find(111);

            User adduser = new User {
                Username   = "******",
                Password   = "******",
                Firstname  = "Greg",
                Lastname   = "Doud",
                Phone      = "513-555-1212",
                Email      = "*****@*****.**",
                Active     = true,
                IsAdmin    = false,
                IsReviewer = false
            };
            //User addedUser = db.Users.Add(adduser);
            //db.SaveChanges();
            //db = new PrsDbContext();

            //var pr1 = new PurchaseRequest {
            //	Description = "First PR",
            //	Justification = "",
            //	DeliveryMode = "Pickup",
            //	UserId = db.Users.SingleOrDefault(u => u.Username == "gdoud").Id
            //};
            //db.PurchaseRequests.Add(pr1);
            //db.SaveChanges();


            var prli1 = new PurchaseRequestLineitem {
                PurchaseRequestId = db.PurchaseRequests.SingleOrDefault(pr => pr.Description == "First PR").Id,
                ProductId         = db.Products.SingleOrDefault(p => p.PartNumber == "Echo").Id,
                Quantity          = 1
            };

            db.PurchaseRequestLineitems.Add(prli1);
            db.SaveChanges();
        }
Ejemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "Id,PurchaseRequestId,ProductId,Quantity")] PurchaseRequestLineitem purchaseRequestLineitem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(purchaseRequestLineitem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId         = new SelectList(db.Products, "Id", "PartNumber", purchaseRequestLineitem.ProductId);
     ViewBag.PurchaseRequestId = new SelectList(db.PurchaseRequests, "Id", "Description", purchaseRequestLineitem.PurchaseRequestId);
     return(View(purchaseRequestLineitem));
 }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,PurchaseRequestId,ProductId,Quantity")] PurchaseRequestLineitem purchaseRequestLineitem)
        {
            if (ModelState.IsValid)
            {
                purchaseRequestLineitem.PurchaseRequestId = (int)TempData["PurchaseRequestId"];
                db.PurchaseRequestLineitems.Add(purchaseRequestLineitem);
                db.SaveChanges();
                return(RedirectToAction("Lines", new { prid = purchaseRequestLineitem.PurchaseRequestId }));
            }

            ViewBag.ProductId         = new SelectList(db.Products, "Id", "PartNumber", purchaseRequestLineitem.ProductId);
            ViewBag.PurchaseRequestId = new SelectList(db.PurchaseRequests, "Id", "Description", purchaseRequestLineitem.PurchaseRequestId);
            return(View(purchaseRequestLineitem));
        }
Ejemplo n.º 8
0
        // GET: PurchaseRequestLineitems/Details/5
        public ActionResult Details(int?prid, int?id)
        {
            if (id == null || prid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PurchaseRequestLineitem purchaseRequestLineitem = db.PurchaseRequestLineitems.Find(id);

            if (purchaseRequestLineitem == null)
            {
                return(HttpNotFound());
            }
            return(View(purchaseRequestLineitem));
        }
Ejemplo n.º 9
0
        // GET: PurchaseRequestLineitems/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PurchaseRequestLineitem purchaseRequestLineitem = db.PurchaseRequestLineitems.Find(id);

            if (purchaseRequestLineitem == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductId         = new SelectList(db.Products, "Id", "PartNumber", purchaseRequestLineitem.ProductId);
            ViewBag.PurchaseRequestId = new SelectList(db.PurchaseRequests, "Id", "Description", purchaseRequestLineitem.PurchaseRequestId);
            return(View(purchaseRequestLineitem));
        }
        public JsonResponse Remove(PurchaseRequestLineitem purchaseRequestLineitem)
        {
            if (purchaseRequestLineitem == null)
            {
                return new JsonResponse {
                           Code = -100, Message = $"purchaseRequestLineitem cannot be null"
                }
            }
            ;
            db.PurchaseRequestLineitems.Attach(purchaseRequestLineitem);
            db.Entry(purchaseRequestLineitem).State = System.Data.Entity.EntityState.Deleted;
            var recsAffected = db.SaveChanges();

            RecalcLineItemTotal(purchaseRequestLineitem.PurchaseRequestId);

            return(new JsonResponse {
                Message = "PurchaseRequestLineitem remove successful!", Data = purchaseRequestLineitem
            });
        }
    }