Example #1
0
 public ActionResult History(string id)
 {
     try
     {
         var model = new ProductModel();
         Product product = _productService.GetDataById(new Guid(id));
         model.Id = product.Id;
         model.Active = product.Active;
         model.Code = product.Code;
         model.Cost = product.Cost;
         model.Name = product.Name;
         model.DateModified = product.DateModified ?? product.DateCreated;
         model.ProductType = product.ProductType;
         model.Description = product.Description;
         ViewBag.RenderCost = string.Format(new CultureInfo("en-PH"), "{0:C}", product.Cost);
         if (product != null)
             return View(model);
     }
     catch (Exception)
     {
     }
     return RedirectToAction("Index");
 }
Example #2
0
 public JsonResult New(ProductModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool ifExists = _productService.CheckDataIfExists(model);
             if (!ifExists)
             {
                 var product = new Product();
                 product.Active = true;
                 product.DateCreated = DateTime.Now;
                 product.CreatedBy = User.Identity.Name;
                 product.Name = model.Name;
                 product.Code = model.Code.ToUpper();
                 product.Cost = model.Cost;
                 product.Description = model.Description;
                 product.ProductType = _productTypeService.GetDataById(new Guid(model.ProductTypeId));
                 product.Id = _productService.Create(product);
                 model.Id = product.Id;
                 return
                     Json(
                         new
                         {
                             result = Base.Encrypt(product.Id.ToString()),
                             message = MessageCode.saved,
                             code = StatusCode.saved,
                             content = product.Name
                         });
             }
             return
                 Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed });
         }
         return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
     }
     catch (Exception ex)
     {
         return
             Json(
                 new
                 {
                     result = StatusCode.failed,
                     message = ex.Message,
                     code = StatusCode.failed,
                     content = model.Name
                 });
     }
 }
Example #3
0
 public JsonResult Manage(ProductModel model)
 {
     try
     {
         string productTypeId = model.ProductTypeId ?? string.Empty;
         model.ProductType = _productTypeService.GetDataById(new Guid(productTypeId));
         if (ModelState.IsValid)
         {
             bool ifExists = _productService.CheckDataIfExists(model);
             if (!ifExists)
             {
                 //product
                 var product = new Product();
                 product = _productService.GetDataById(model.Id);
                 decimal previousCost = product.Cost;
                 decimal latestCost = model.Cost;
                 product.Code = model.Code.ToUpper();
                 product.Cost = latestCost;
                 product.Description = model.Description;
                 product.Name = model.Name;
                 product.Active = model.Active;
                 product.DateModified = DateTime.Now;
                 product.ModifiedBy = User.Identity.Name;
                 _productService.SaveChanges(product);
                 //save to history
                 bool costChanged = !previousCost.Equals(latestCost);
                 if (costChanged)
                 {
                     var productHistory = new ProductHistory();
                     productHistory.Cost = model.Cost;
                     productHistory.Product = product;
                     productHistory.DateModified = DateTime.Now;
                     productHistory.ModifiedBy = User.Identity.Name;
                     _productHistoryService.Save(productHistory);
                 }
                 return
                     Json(
                         new
                         {
                             result = Base.Encrypt(product.Id.ToString()),
                             message = MessageCode.modified,
                             code = StatusCode.modified,
                             content = product.Name
                         });
             }
             return
                 Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed });
         }
         return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
     }
     catch (Exception ex)
     {
         return Json(new { result = StatusCode.failed, message = ex.Message, code = StatusCode.failed });
     }
 }
Example #4
0
 public ActionResult New()
 {
     var product = new ProductModel();
     product.ProductTypeList = _service.GetProductTypeList(new Guid());
     return View(product);
 }
Example #5
0
 public ActionResult Manage(string id)
 {
     try
     {
         var model = new ProductModel();
         Product product = _productService.GetDataById(new Guid(id));
         model.Id = product.Id;
         model.Active = product.Active;
         model.Code = product.Code;
         model.Cost = product.Cost;
         model.Name = product.Name;
         model.Description = product.Description;
         model.ProductTypeList = _service.GetProductTypeList(product.ProductType.Id);
         if (product != null)
             return View(model);
     }
     catch (Exception)
     {
     }
     return RedirectToAction("Index");
 }