public bool Update(Batch_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = _context.Batches.Where(batch => batch.BatchID == model.BatchID).FirstOrDefault();
             data.BatchName         = model.BatchName;
             data.ProductCategoryId = model.ProductCategoryId;
             data.ProductID         = model.ProductID;
             data.QunatityProduced  = model.QunatityProduced;
             data.UnitPrice         = model.UnitPrice;
             data.StockLeft         = model.StockLeft;
             data.DateProduced      = model.DateProduced;
             data.ExpiryDate        = model.ExpiryDate;
             data.DateUpdated       = DateTime.Now;
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
 public bool Save(Batch_Model model)
 {
     using (var _context = new SalesTrackingSystemEntities())
     {
         try
         {
             var data = new Batch()
             {
                 BatchID           = GetNewBatchID(),
                 BatchName         = model.BatchName,
                 ProductCategoryId = model.ProductCategoryId,
                 ProductID         = model.ProductID,
                 QunatityProduced  = model.QunatityProduced,
                 UnitPrice         = model.UnitPrice,
                 StockLeft         = Convert.ToInt64(model.QunatityProduced),
                 DateProduced      = model.DateProduced,
                 ExpiryDate        = model.ExpiryDate,
                 DateCreated       = DateTime.Now
             };
             _context.Batches.Add(data);
             _context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Exemple #3
0
 public ActionResult BatchAdd(Batch_Model batch_Model)
 {
     if (string.IsNullOrEmpty(batch_Model.BatchName))
     {
         ViewBag.AddBatchError = "Error";
         return(View("Batch"));
     }
     else
     {
         if (Batch_.Save(batch_Model))
         {
             Session["Success"] = batch_Model.BatchName + " added successfully!!";
         }
         else
         {
             Session["Error"] = batch_Model.BatchName + " couldn't be added please retry!!";
         }
         return(RedirectToAction("Batch"));
     }
 }
Exemple #4
0
        public ActionResult BatchDelete(Batch_Model batch_Model)
        {
            var Batch_Name = batch_Model.BatchName;

            try
            {
                if (Batch_.Delete(batch_Model.BatchID))
                {
                    return(Json(Batch_Name + " batch has been deleted successfully"));
                }
                else
                {
                    return(Json("Error"));
                }
            }
            catch (Exception e)
            {
                return(Json("Error" + e.ToString()));
            }
        }
Exemple #5
0
 public ActionResult BatchUpdate(Batch_Model batch_Model)
 {
     if (string.IsNullOrEmpty(batch_Model.BatchName))
     {
         ViewBag.UpdateBatchError = "Error";
         ViewBag.UpdateBatchData  = batch_Model.BatchID;
         return(View("Batch"));
     }
     else
     {
         if (Batch_.Update(batch_Model))
         {
             Session["Success"] = batch_Model.BatchName + " updated successfully!!";
             return(RedirectToAction("Batch"));
         }
         else
         {
             Session["Error"] = batch_Model.BatchName + " couldn't be updated please retry!!";
             return(View("Batch"));
         }
     }
 }