public ProductHistory ToProductHistory(Product product = null)
        {
            var result = new ProductHistory();

            result.Barcode           = this.Barcode;
            result.Unit              = this.Unit;
            result.NameNew           = this.ProductName;
            result.QuantityNew       = this.Quantity;
            result.PriceNew          = this.Price;
            result.SupplierIdNew     = Supplier;
            result.ExpirationDateNew = Ex;
            result.PriceBuyNew       = this.PriceBuy;
            result.InterestNew       = this.Interest;
            result.Status            = Constants.INSERT;
            if (product != null)
            {
                result.NameOld           = product.Name;
                result.PriceOld          = product.Price;
                result.PriceBuyOld       = product.PriceBuy;
                result.InterestOld       = product.Interest;
                result.QuantityOld       = product.Quantity;
                result.ExpirationDateOld = product.ExpirationDate;
                result.Status            = Constants.UPDATE;
                result.QuantityNew       = this.Quantity + product.Quantity;
                result.SupplierIdOld     = product.SupplierId;
            }
            result.CreatedAt = DateTime.Now;
            result.CreatedBy = "Administrator";
            return(result);
        }
Exemple #2
0
 public Product(ProductHistory productHistory)
 {
     this.Id       = productHistory.Id;
     this.Name     = productHistory.Name;
     this.Price    = productHistory.Price;
     this.Quantity = productHistory.Quantity;
 }
Exemple #3
0
        public void DeleteProductHistoriesById(int productHistoriesId)
        {
            ProductHistory productHistories = GetProductHistoriesById(productHistoriesId);

            Context.ProductHistories.Remove(productHistories);
            Context.SaveChanges();
        }
        public HttpResponseMessage Post()
        {
            String filename            = "";
            HttpResponseMessage result = null;
            var httpRequest            = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                var docfiles = new List <string>();
                for (int i = 0; i < httpRequest.Files.Count; i++)
                {
                    var postedFile = httpRequest.Files[i];
                    var filePath   = HttpContext.Current.Server.MapPath("~/content/image/" + postedFile.FileName);
                    filename += postedFile.FileName + '|';
                    postedFile.SaveAs(filePath);

                    docfiles.Add(filePath);
                }

                Product product = productRepository.Get(pid);
                product.ImageFile = filename.Remove(filename.Length - 1, 1);
                productRepository.Update(product);

                ProductHistory phis = producthistory.Get(phid);
                phis.ImageFile = filename.Remove(filename.Length - 1, 1);
                producthistory.Update(phis);
                result = Request.CreateResponse(HttpStatusCode.Created, product);
            }
            else
            {
                result = Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            return(result);
        }
Exemple #5
0
        public ActionResult Edit(CreateProductHistoryViewModel model)
        {
            var            productHistoryToUpdate = new ProductHistory();
            ProductHistory newProductHistory      = new ProductHistory()
            {
                ProductID = model.ProductID,
                HistoryID = model.HistoryID,
                Comment   = model.Comment,
                Date      = model.DateTimeNow,
                UserID    = model.Email
            };
            var  product = _unityOfWork.Product.getProductWithHistory(model.ProductID);
            long id      = product.ID;

            // find history entry in list of histories
            foreach (var productHistory in product.ProductHistories)
            {
                // a unique history entry is given by ProductID, HistoryID, Date
                if (productHistory.Date.ToString() == model.DateTimeNow.ToString() && model.OldHistoryID == productHistory.HistoryID && model.Email == productHistory.UserID)
                {
                    productHistoryToUpdate = productHistory;
                    break;
                }
            }
            product.ProductHistories.Remove(productHistoryToUpdate);
            product.ProductHistories.Add(newProductHistory);
            _unityOfWork.Product.Update(product);
            _unityOfWork.Save();
            newProductHistory.User   = null;
            newProductHistory.UserID = null;
            LoggingController.writeLog(newProductHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());
            return(RedirectToAction("Details", new { id = id }));
        }
        public async Task <JsonResult> QuickAddHistory(CreateProductHistoryViewModel model)
        {
            if (model.UploadFile != null)
            {
                var uploads = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads");



                if (model.UploadFile.Length > 0)

                {
                    using (var fileStream = new FileStream(Path.Combine(uploads, model.UploadFile.FileName), FileMode.Create))

                    {
                        await model.UploadFile.CopyToAsync(fileStream);
                    }
                    Upload myFile = new Upload()
                    {
                        RelativPath = Path.Combine(uploads, model.UploadFile.FileName),
                        Size        = model.UploadFile.Length.ToString(),
                        Format      = model.UploadFile.ContentType.ToString(),
                    };
                    _unityOfWork.Upload.Insert(myFile);
                    _unityOfWork.Save();
                    model.UploadID = myFile.ID;
                }
            }



            try
            {
                Product        product        = _unityOfWork.Product.GetById(model.ProductID);
                ProductHistory productHistory = new ProductHistory
                {
                    UserID    = _db.Users.FirstOrDefault(x => x.Email == model.Email).Id,
                    Comment   = model.Comment,
                    Date      = DateTime.Now,
                    ProductID = model.ProductID,
                    HistoryID = model.HistoryID,
                    FileID    = model.UploadID
                };



                product.ProductHistories.Add(productHistory);
                _unityOfWork.Product.Update(product);
                _unityOfWork.Save();
                productHistory.User   = null;
                productHistory.UserID = null;
                LoggingController.writeLog(productHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());
                return(Json(productHistory));
            }
            catch
            {
                return(Json(null));
            }
        }
Exemple #7
0
        public async Task <ActionResult> GetProductHistory()
        {
            ViewBag.Categories = _mapper.Map <List <CategoryViewModel> >(
                (await _categoryService.GetCategories()).ToList());

            var productHistory = new ProductHistory(HttpContext);

            return(View(productHistory.GetOrCreateProductList()));
        }
Exemple #8
0
        public void UpdateProductHistoriesByProductHistories(ProductHistory productHistory)
        {
            var ProductHistories = GetProductHistoriesById(productHistory.ProductHistoryId);

            if (ProductHistories != null)
            {
            }
            Context.SaveChanges();
        }
 public async void HandleProductCreation([FromBody] HSProductCreatePayload payload)
 {
     var update = new ProductHistory()
     {
         Action     = ActionType.Create,
         ResourceID = payload.Response.Body.ID,
         Resource   = payload.Response.Body,
     };
     await _productQuery.Post(update);
 }
        public void PartialHistoryUpdate(ProductHistory product)
        {
            var item = context.Set <ProductHistory>().Find(product.Product_id);

            item.ImageFile    = product.ImageFile;
            item.Description  = product.Description;
            item.UnitPrice    = product.UnitPrice;
            item.Product_name = product.Product_name;
            ProductHistoryUpdate(item);
        }
 public async void HandleProductUpdate([FromBody] HSProductUpdatePayload payload)
 {
     Console.WriteLine(payload);
     var update = new ProductHistory()
     {
         Action     = ActionType.Update,
         ResourceID = payload.Response.Body.ID,
         Resource   = payload.Response.Body,
     };
     await _productQuery.Put(update);
 }
Exemple #12
0
        public async Task <ActionResult> RollbackProduct(int id)
        {
            var productHistory = new ProductHistory(HttpContext);

            await _productService.EditProduct(
                _mapper.Map <ProductDTO>(
                    productHistory.GetProductId(id))
                );

            productHistory.ReturnProduct(id);

            return(RedirectToAction(nameof(GetProductList)));
        }
        public async Task <IActionResult> AddHistory(CreateProductHistoryViewModel model)
        {
            if (model.UploadFile != null)
            {
                var uploads = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads");

                if (model.UploadFile.Length > 0)

                {
                    string fName             = Path.GetFileNameWithoutExtension(model.UploadFile.FileName);
                    string fExt              = Path.GetExtension(model.UploadFile.FileName);
                    string hashCode          = RandomString(5);
                    string newUniqueFileName = String.Concat(fName, "_" + hashCode, fExt);

                    using (var fileStream = new FileStream(Path.Combine(uploads, newUniqueFileName), FileMode.Create))

                    {
                        await model.UploadFile.CopyToAsync(fileStream);
                    }
                    Upload myFile = new Upload()
                    {
                        RelativPath = Path.Combine(uploads, newUniqueFileName),
                        Size        = model.UploadFile.Length.ToString(),
                        Format      = model.UploadFile.ContentType.ToString(),
                    };
                    _unityOfWork.Upload.Insert(myFile);
                    _unityOfWork.Save();
                    model.UploadID = myFile.ID;
                }
            }
            Product        product        = _unityOfWork.Product.GetById(model.ProductID);
            ProductHistory productHistory = new ProductHistory
            {
                UserID    = _db.Users.FirstOrDefault(x => x.Email == model.Email).Id,
                Comment   = model.Comment,
                Date      = DateTime.Now,
                ProductID = model.ProductID,
                HistoryID = model.HistoryID,
                FileID    = model.UploadID
            };

            product.ProductHistories.Add(productHistory);
            _unityOfWork.Product.Update(product);
            _unityOfWork.Save();
            productHistory.User   = null;
            productHistory.UserID = null;
            LoggingController.writeLog(productHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());
            return(Redirect(Request.Headers["Referer"]));
        }
        public IHttpActionResult Post(int id)
        {
            TempOrderProduct temporderProduct = temporderProductRepository.Get(id);
            var       pid    = temporderProduct.ProductID;
            TempOrder torder = temporderrepo.Get(Convert.ToInt32(temporderProductRepository.Get(id).TempOrderId));

            temporderProductRepository.Delete(temporderProductRepository.Get(id).TempOrderProductID);
            temporderrepo.Delete(Convert.ToInt32(torder.TempOrderId));


            Order order = new Order();

            order.date          = DateTime.Now;
            order.PayMentMethod = torder.PayMentMethod;
            order.Quantity      = torder.Quantity;
            order.Size          = torder.Size;
            order.totalAmount   = torder.totalAmount;
            orderrepo.Insert(order);


            OrderProduct orderProduct = new OrderProduct();

            orderProduct.ProductHistoryId = producthis.GetByProductNameCategory(productrepo.Get(Convert.ToInt32(pid)).Product_name, productrepo.Get(Convert.ToInt32(pid)).MainCategoryId).ProductHistoryId;
            orderProduct.CustomerID       = temporderProduct.CustomerID;
            orderProduct.OrderID          = order.OrderID;
            productorderrepo.Insert(orderProduct);

            Profit profit = new Profit();

            ProductHistory phis = producthis.Get(orderProduct.ProductHistoryId);

            profit.OrderProductId = orderProduct.OrderProductId;
            if (phis.Sale != null)
            {
                var p  = (double)phis.UnitPrice;
                var v  = Convert.ToDouble(phis.Sale.Amount) / 100;
                var c1 = (p - (p * v));
                profit.ProfitAmount = ((decimal)c1 - phis.Cost) * order.Quantity;
            }
            else
            {
                profit.ProfitAmount = (phis.UnitPrice - phis.Cost) * order.Quantity;
            }


            profitrepo.Insert(profit);

            return(Ok("success"));
        }
Exemple #15
0
        public async Task <ActionResult> ProductEdit(int?id)
        {
            var product = _mapper.Map <ProductViewModel>(
                await _productService.GetProduct(id));

            var history = new ProductHistory(HttpContext);

            history.AddProduct(product);

            ViewBag.Categories = new SelectList(
                _mapper.Map <IEnumerable <CategoryViewModel> >
                    (await _categoryService.GetCategories()), "Id", "Name");

            return(View(product));
        }
        public ActionResult Confirmorder(int id)
        {
            TempOrderProduct temporderProduct = temporderProductRepository.Get(id);
            TempOrder        torder           = temporderrepo.Get(temporderProductRepository.Get(id).OrderID);

            temporderProductRepository.Delete(temporderProductRepository.Get(id).ProductOrderID);
            temporderrepo.Delete(temporderProduct.OrderID);


            Order order = new Order();

            order.date          = DateTime.Now;
            order.PayMentMethod = torder.PayMentMethod;
            order.Quantity      = torder.Quantity;
            order.Size          = torder.Size;
            order.totalAmount   = torder.totalAmount;
            orderrepo.Insert(order);


            OrderProduct orderProduct = new OrderProduct();

            orderProduct.ProductID  = temporderProduct.ProductID;
            orderProduct.CustomerID = temporderProduct.CustomerID;
            orderProduct.OrderID    = order.OrderID;
            productorderrepo.Insert(orderProduct);

            Profit profit = new Profit();

            ProductHistory phis = producthis.Get(orderProduct.ProductID);

            profit.ProductOrderID = orderProduct.ProductOrderID;
            if (phis.Sale != null)
            {
                var p  = (double)phis.UnitPrice;
                var v  = Convert.ToDouble(phis.Sale.Amount) / 100;
                var c1 = (p - (p * v));
                profit.ProfitAmount = ((decimal)c1 - phis.Cost) * order.Quantity;
            }
            else
            {
                profit.ProfitAmount = (phis.UnitPrice - phis.Cost) * order.Quantity;
            }


            profitrepo.Insert(profit);

            return(Json("success"));
        }
Exemple #17
0
        private static void Iterator()
        {
            ProductHistory productHistory = new ProductHistory();

            productHistory.Push("a");
            productHistory.Push("b");
            productHistory.Push("c");
            IIterator <string> it = productHistory.CreateIterator();

            while (it.HasNext())
            {
                string product = it.Current();
                Console.WriteLine(product);
                it.Next();
            }
        }
        public ActionResult AddProductToSale(Sale sale, int Product_id)
        {
            sale.StartDate = DateTime.Now;
            salerepo.Insert(sale);
            SaleHistory salehis = new SaleHistory();

            salehis.Amount    = sale.Amount;
            salehis.StartDate = sale.StartDate;
            saleHistoryRepo.Insert(salehis);
            Product x = product.Get(Product_id);

            x.SaleID = sale.SaleID;
            product.Update(x);
            ProductHistory xh = producthis.GetByProductNameCategory(product.Get(Product_id).Product_name, product.Get(Product_id).CategoryID);

            xh.SaleID = salehis.SaleID;
            producthis.Update(xh);
            return(RedirectToAction("Index"));
        }
 public ActionResult Details(int id)
 {
     if (Session["LoginID"] != null)
     {
         List <OrderProduct> orderProductList = new List <OrderProduct>();
         ProductHistory      producthis       = productHistory.GetByProductNameCategory(product.Get(id).Product_name, product.Get(id).CategoryID);
         int pid = producthis.Product_id;
         orderProductList = OrderProduct.GetByCustomerId((int)Session["LoginID"], pid);
         if (orderProductList.Count == 0)
         {
             Session["notbuy"] = "In order to review you need to Buy this product";
         }
         else
         {
             Session["notbuy"] = null;
         }
     }
     return(View(product.Get(id)));
 }
Exemple #20
0
        private void LoadPortalView()
        {
            var products = SessionDataContext.Products
                           .Where(x => x.Keyword == _Keyword && x.ProductName == _ProductName);

            foreach (var product in products)
            {
                ProductHistory pH = new ProductHistory();
                pH.Keyword     = product.Keyword;
                pH.Note        = (_SelectedProduct == null) ? string.Empty : _SelectedProduct.Note;
                pH.Portal      = product.Portal;
                pH.ProductId   = product.ProductId;
                pH.ProductName = product.ProductName;
                pH.Rank        = product.Rank;
                pH.Review      = (_SelectedProduct == null) ? string.Empty : _SelectedProduct.Review;
                var itemVM = new PortalViewItemVM(VMSession, pH);
                _PortalViewItems.Add(itemVM);
                AddChildVM(itemVM);
            }
        }
Exemple #21
0
        private void SeedProducts(ApplicationDbContext context, int clientId, string createdByUserId)
        {
            var productNames = new List <string>
            {
                "Dyed Diesel",
                "Dyed Gas",
                "Clear Diesel",
                "Clear Gas"
            };

            foreach (var name in productNames)
            {
                var product = new Product()
                {
                    Name            = name,
                    ClientId        = clientId,
                    CreatedByUserId = createdByUserId,
                    CreatedDate     = DateTime.UtcNow,
                    Status          = Status.Active,
                    Notes           = string.Empty
                };
                context.Products.AddOrUpdate(product);
                // have to call it here to get the new productId
                context.SaveChanges();

                var productHistory = new ProductHistory()
                {
                    ProductId        = product.Id,
                    Name             = name,
                    ClientId         = clientId,
                    ModifiedByUserId = createdByUserId,
                    ModifiedDate     = product.CreatedDate,
                    Status           = Status.Active,
                    Notes            = string.Empty
                };

                context.ProductsHistory.AddOrUpdate(productHistory);
                context.SaveChanges();
            }
        }
Exemple #22
0
        public ActionResult Delete(int productId, string userId, DateTime date, int historyId)
        {
            var productHistoryToDelete = new ProductHistory();
            var product = _unityOfWork.Product.getProductWithHistory(productId);
            int id      = productId;

            foreach (var productHistory in product.ProductHistories)
            {
                if (date.ToString() == productHistory.Date.ToString() && historyId == productHistory.HistoryID && userId == productHistory.UserID)
                {
                    productHistoryToDelete = productHistory;
                    break;
                }
            }
            product.ProductHistories.Remove(productHistoryToDelete);
            _unityOfWork.Product.Update(product);
            _unityOfWork.Save();
            productHistoryToDelete.User   = null;
            productHistoryToDelete.UserID = null;
            LoggingController.writeLog(productHistoryToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString());
            return(RedirectToAction("Details", new { id = id }));
        }
        public IHttpActionResult Post(Product product)
        {
            if (product.SubCategoryID != null)
            {
                product.MainCategoryId = SubCategory.Get((int)product.SubCategoryID).MainCategoryId;
            }
            if (product.FinalSubCategoryID != null)
            {
                product.SubCategoryID  = FinalSub.Get((int)product.FinalSubCategoryID).SubCategoryId;
                product.MainCategoryId = SubCategory.Get((int)product.SubCategoryID).MainCategoryId;
            }


            product.AddedDate = DateTime.Now;
            product.ImageFile = "0";
            productRepository.Insert(product);

            ProductHistory Phistory = new ProductHistory();

            Phistory.AddedDate          = product.AddedDate;
            Phistory.OnHand             = product.OnHand;
            Phistory.Product_name       = product.Product_name;
            Phistory.UnitPrice          = product.UnitPrice;
            Phistory.Description        = product.Description;
            Phistory.ImageFile          = product.ImageFile;
            Phistory.Cost               = product.Cost;
            Phistory.MainCategoryId     = product.MainCategoryId;
            Phistory.SubCategoryID      = product.SubCategoryID;
            Phistory.FinalSubCategoryID = product.FinalSubCategoryID;
            Phistory.SizeCategory       = product.SizeCategory;
            producthistory.Insert(Phistory);

            pid  = product.ProductId;
            phid = Phistory.ProductHistoryId;

            return(Ok(product));
        }
Exemple #24
0
 public void Add(ProductHistory productHistory)
 {
     Context.ProductHistories.Add(productHistory);
     Context.SaveChanges();
 }
 public ProductHistory GetByExpression(ProductHistory entity)
 {
     throw new NotImplementedException();
 }
Exemple #26
0
 public IList <ProductHistoryData> GetAllHistory(Guid id)
 {
     return(ProductHistory.ToJavaScriptProductHistory(_eventStoreRepository.All(id)));
 }
 public PortalViewItemVM(ViewModelSession vmSession, ProductHistory productHistory)
 {
     _ProductHistory = productHistory;
 }
 public void Save(ProductHistory entity)
 {
     _productHistoryRepository.SaveOrUpdate(entity);
 }
 public void SaveChanges(ProductHistory entity)
 {
     throw new NotImplementedException();
 }
 private void ProductHistoryUpdate(ProductHistory product)
 {
     context.Entry(product).State = EntityState.Modified;
     context.SaveChanges();
 }
Exemple #31
0
        public ActionResult AddProduct(Product product, HttpPostedFileBase[] files)
        {
            if (Session["admin"] == null)
            {
                return(RedirectToAction("index", "Home"));
            }
            if (ModelState.IsValid)
            {
                if (product.SubCategoryID != null)
                {
                    product.CategoryID = SubCategory.Get((int)product.SubCategoryID).MCategory_id;
                }
                if (product.FinalSubCategoryID != null)
                {
                    product.SubCategoryID = FinalSub.Get((int)product.FinalSubCategoryID).SubCate_id;
                    product.CategoryID    = SubCategory.Get((int)product.SubCategoryID).MCategory_id;
                }
                if (productRepository.GetByProductName(product.Product_name, (int)product.CategoryID))
                {
                    ViewData["errorm"] = "product name already exist!";
                    return(Json(new
                    {
                        newUrl = Url.Action("AddProduct")
                    }
                                ));
                }
                String filename = "";
                //iterating through multiple file collection
                foreach (HttpPostedFileBase file in files)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        try
                        {
                            string path = System.IO.Path.Combine(Server.MapPath("~/content/image"), System.IO.Path.GetFileName(file.FileName));
                            file.SaveAs(path);
                            filename += System.IO.Path.GetFileName(file.FileName) + '|';
                        }
                        catch (Exception exp)
                        {
                            ViewBag.Message = "ERROR:" + exp.Message.ToString();
                            return(Json(new
                            {
                                newUrl = Url.Action("AddProduct")
                            }
                                        ));
                        }
                    }
                }
                product.AddedDate = DateTime.Now;
                product.ImageFile = filename.Remove(filename.Length - 1, 1);
                productRepository.Insert(product);

                ProductHistory Phistory = new ProductHistory();
                Phistory.AddedDate          = product.AddedDate;
                Phistory.OnHand             = product.OnHand;
                Phistory.Product_name       = product.Product_name;
                Phistory.UnitPrice          = product.UnitPrice;
                Phistory.Description        = product.Description;
                Phistory.ImageFile          = product.ImageFile;
                Phistory.Cost               = product.Cost;
                Phistory.CategoryID         = product.CategoryID;
                Phistory.SubCategoryID      = product.SubCategoryID;
                Phistory.FinalSubCategoryID = product.FinalSubCategoryID;
                Phistory.SizeCategory       = product.SizeCategory;
                producthistory.Insert(Phistory);
                if (product.SizeCategory == "other")
                {
                    return(Json(new
                    {
                        newUrl = Url.Action("Index")
                    }
                                ));
                }
                else
                {
                    return(Json(new
                    {
                        newUrl = Url.Action("AddSize", new { id = product.Product_id }) //Payment as Action; Process as Controller
                    }
                                ));
                }
            }
            ViewData["MainCatagories"] = mainCategoryRepository.GetAll().ToList();
            Session["ProductError"]    = ModelState
                                         .Where(x => x.Value.Errors.Count > 0)
                                         .ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                );
            Session["product"] = product;
            return(Json(new
            {
                newUrl = Url.Action("AddProduct") //Payment as Action; Process as Controller
            }
                        ));
        }
Exemple #32
0
        public ProductHistory GetProductHistoriesById(int productHistoriesId)
        {
            ProductHistory productHistory = Context.ProductHistories.FirstOrDefault(x => x.ProductHistoryId == productHistoriesId);

            return(productHistory);
        }
 public Guid Create(ProductHistory entity)
 {
     throw new NotImplementedException();
 }
 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 });
     }
 }
Exemple #35
0
        public ActionResult UpdateProduct(FormCollection formCollection, HttpPostedFileBase[] files)
        {
            String  filename = "";
            Product product  = new Product();

            //iterating through multiple file collection

            foreach (HttpPostedFileBase file in files)
            {
                if (file != null && file.ContentLength > 0)
                {
                    try
                    {
                        string path = System.IO.Path.Combine(Server.MapPath("~/content/image"), System.IO.Path.GetFileName(file.FileName));
                        file.SaveAs(path);
                        filename += System.IO.Path.GetFileName(file.FileName) + '|';
                    }
                    catch (Exception exp)
                    {
                        ViewBag.Message = "ERROR:" + exp.Message.ToString();
                        return(Json(new
                        {
                            newUrl = Url.Action("Index")
                        }
                                    ));
                    }
                }
                else
                {
                    filename = productRepository.Get(Convert.ToInt32(formCollection["Product_id"])).ImageFile;
                    break;
                }
            }

            product.ImageFile = filename;
            foreach (var key in formCollection.AllKeys)
            {
                if (key == "Product_id")
                {
                    product.Product_id = Convert.ToInt32(formCollection[key]);
                }
                else if (key == "Product_name")
                {
                    product.Product_name = formCollection[key];
                }
                else if (key == "Description")
                {
                    product.Description = formCollection[key];
                }
                else if (key == "UnitPrice")
                {
                    product.UnitPrice = (Convert.ToDecimal(formCollection[key]));
                }
                else if (key == "OnHand")
                {
                    product.OnHand = (Convert.ToInt32(formCollection[key]));
                }
            }
            ProductHistory Phistory = new ProductHistory();

            Phistory.Product_id = sizehistory.GetByProductNameCategory(productRepository.Get(product.Product_id).Product_name, productRepository.Get(product.Product_id).CategoryID).Product_id;
            if (product.OnHand != null)
            {
                Phistory.OnHand = product.OnHand;
            }
            Phistory.Product_name       = product.Product_name;
            Phistory.UnitPrice          = product.UnitPrice;
            Phistory.Description        = product.Description;
            Phistory.Cost               = product.Cost;
            Phistory.CategoryID         = product.CategoryID;
            Phistory.ImageFile          = product.ImageFile;
            Phistory.SubCategoryID      = product.SubCategoryID;
            Phistory.FinalSubCategoryID = product.FinalSubCategoryID;
            Phistory.SizeCategory       = product.SizeCategory;
            producthistory.PartialHistoryUpdate(Phistory);
            productRepository.PartialUpdate(product);
            return(View("Index"));
        }
 public void SaveOrUpdate(ProductHistory entity)
 {
     throw new NotImplementedException();
 }