Beispiel #1
0
 public ActionResult AddItem(Item itm)
 {
     using (EntitiesAPSCS db = new EntitiesAPSCS())
     {
         if (itm.ItemID == 0)
         {
             if (db.Items.Any(x => x.ItemPart == itm.ItemPart))
             {
                 return(Json(new { success = false, message = "Item Part Number Already Exist!" }, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 db.Items.Add(itm);
                 db.SaveChanges();
                 return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             db.Entry(itm).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
        public ActionResult AddUsers(User usr)
        {
            using (EntitiesAPSCS db = new EntitiesAPSCS())
            {
                if (usr.UserID == 0)
                {
                    // check input ID is already exist
                    if (db.Users.Any(x => x.IDCard == usr.IDCard))
                    {
                        return(Json(new { success = false, message = "IDCard Number Already Exist!" }, JsonRequestBehavior.AllowGet));
                    }

                    else
                    { // New user added
                        db.Users.Add(usr);
                        db.SaveChanges();
                        return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {// Edit user updated
                    db.Entry(usr).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Beispiel #3
0
 public ActionResult EditItem(Item itm)
 {
     using (EntitiesAPSCS db = new EntitiesAPSCS())
     {
         db.Entry(itm).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #4
0
        public ActionResult EditStockOut(StockOut stkout)
        {
            using (EntitiesAPSCS db = new EntitiesAPSCS())
            {
                var stkoutID = db.StockOuts.Find(stkout.StockOutID);

                var PartIDmatch = db.Items.Any(x => x.ItemPart.Equals(stkout.StockOutPart));
                var GetItem     = db.Items.FirstOrDefault(x => x.ItemPart == stkout.StockOutPart);
                var GetSqty     = db.StockOuts.FirstOrDefault(x => x.StockOutPart == stkout.StockOutPart);


                if (!db.Items.Any(x => x.ItemPart == stkout.StockOutPart))
                {
                    return(Json(new { success = false, message = "Item Part Number Not Found!" }, JsonRequestBehavior.AllowGet));
                }

                //else if (GetItem.ItemQuantity <= 10)
                //{


                //}

                else if (stkout.StockOutQuantity > GetItem.ItemQuantity)
                {
                    return(Json(new { success = false, message = "Not Enough Stock Quantity!" }, JsonRequestBehavior.AllowGet));
                }

                else if (PartIDmatch == true && stkout.StockOutQuantity != null)
                {
                    GetItem.ItemQuantity = (GetItem.ItemQuantity + GetSqty.StockOutQuantity.Value) - stkout.StockOutQuantity.Value;

                    db.Entry(stkoutID).CurrentValues.SetValues(stkout);
                    db.Entry(stkoutID).State = EntityState.Modified;

                    db.SaveChanges();
                    return(Json(new { success = true, message = "Record & Stock Quantity Updated Successfully!" }, JsonRequestBehavior.AllowGet));
                }

                return(View());
            }
        }
Beispiel #5
0
 public ActionResult AddOrEditSupplier(Supplier emp)
 {
     using (EntitiesAPSCS db = new EntitiesAPSCS())
     {
         if (emp.SupplierID == 0)
         {
             db.Suppliers.Add(emp);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(emp).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }