public void Create_ProductMetricNonExisting_ThrowsArgumentException()
        {
            //Arrange
            ProductSize invalidProductSize = new ProductSize
            {
                ProductMetric = new ProductMetric {
                    Id = 1
                },
                Size         = "L",
                MetricXValue = 70,
                MetricYValue = 100,
                MetricZValue = 75
            };

            ProductMetric nullProductMetric = null;

            Mock <IProductSizeRepository>   productSizeRepository   = new Mock <IProductSizeRepository>();
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(invalidProductSize.ProductMetric.Id)).
            Returns(nullProductMetric);
            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            Action actual = () => productSizeService.Create(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Create_IdSpecified_ThrowsArgumentException()
        {
            //Arrange
            ProductSize invalidProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = new ProductMetric {
                    Id = 1
                },
                Size         = "L",
                MetricXValue = 70,
                MetricYValue = 100,
                MetricZValue = 75
            };

            Mock <IProductSizeRepository>   productSizeRepository   = new Mock <IProductSizeRepository>();
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();
            IProductSizeService             productSizeService      = new ProductSizeService(productSizeRepository.Object,
                                                                                             productMetricRepository.Object);

            //Act
            Action actual = () => productSizeService.Create(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Delete_IdExisting_ReturnsDeletedProductSizeWithSpecifiedId()
        {
            //Arrange
            int         existingId = 12;
            ProductSize expected   = new ProductSize
            {
                Id            = existingId,
                ProductMetric = new ProductMetric {
                    Id = 1
                },
                Size         = "XL",
                MetricXValue = 70,
                MetricYValue = -13,
                MetricZValue = 20
            };

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Delete(existingId)).
            Returns(expected);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            ProductSize actual = productSizeService.Delete(existingId);

            //Assert
            Assert.Equal(expected, actual);
        }
 public ActionResult ViewProductSize(int id)
 {
     if (id > 0)
     {
         var model = new ProductSizeService().GetProductSize(id);
         return(View(model));
     }
     return(View());
 }
        public void Create_ProductSizeValid_ReturnsCreatedProductSizeWithId()
        {
            //Arrange
            ProductSize validProductSize = new ProductSize
            {
                ProductMetric = new ProductMetric {
                    Id = 1
                },
                Size         = "L",
                MetricXValue = 70,
                MetricYValue = 100,
                MetricZValue = 75
            };
            ProductSize expected = new ProductSize
            {
                Id            = 1,
                ProductMetric = new ProductMetric {
                    Id = 1
                },
                Size         = "L",
                MetricXValue = 70,
                MetricYValue = 100,
                MetricZValue = 75
            };

            ProductMetric fetchedProductMetric = new ProductMetric
            {
                Id      = 1,
                Name    = "Oversized Hoodie",
                MetricX = "Length",
                MetricY = "Width",
                MetricZ = "Sleeve Length"
            };

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Create(validProductSize)).
            Returns(expected);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(validProductSize.ProductMetric.Id)).
            Returns(fetchedProductMetric);

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            ProductSize actual = productSizeService.Create(validProductSize);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void Update_ProductSizeValid_ReturnsUpdatedProductSize()
        {
            //Arrange
            ProductSize validProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = null,
                Size          = "L",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 75
            };

            ProductSize expected = validProductSize;

            ProductMetric fetchedProductMetric = new ProductMetric {
                Id = 1, MetricX = "Length", MetricY = "Width", MetricZ = "Sleeve Length"
            };

            ProductSize fetchedProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = fetchedProductMetric,
                Size          = "XL",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 150
            };

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Read(validProductSize.Id)).
            Returns(expected);
            productSizeRepository.Setup((repo => repo.ReadIncludeProductMetric(validProductSize.Id)))
            .Returns(fetchedProductSize);
            productSizeRepository.Setup(repo => repo.Update(validProductSize)).
            Returns(expected);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            ProductSize actual = productSizeService.Update(validProductSize);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void Create_ProductSizeNull_ThrowsArgumentNullException()
        {
            //Arrange
            ProductSize invalidProductSize = null;

            Mock <IProductSizeRepository>   productSizeRepository   = new Mock <IProductSizeRepository>();
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();
            IProductSizeService             productSizeService      = new ProductSizeService(productSizeRepository.Object,
                                                                                             productMetricRepository.Object);

            //Act
            Action actual = () => productSizeService.Create(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentNullException>(actual);
        }
        public void Update_IdNonExisting_ThrowsArgumentException()
        {
            //Arrange
            ProductSize invalidProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = null,
                Size          = "L",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 75
            };

            ProductSize nullProductSize = null;

            ProductMetric fetchedProductMetric = new ProductMetric {
                Id = 1, MetricX = "Length", MetricY = "Width", MetricZ = "Sleeve Length"
            };

            ProductSize fetchedProductSize = new ProductSize
            {
                Id            = 1,
                ProductMetric = fetchedProductMetric,
                Size          = "XL",
                MetricXValue  = 70,
                MetricYValue  = 100,
                MetricZValue  = 150
            };

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Read(invalidProductSize.Id)).
            Returns(nullProductSize);
            productSizeRepository.Setup((repo => repo.ReadIncludeProductMetric(invalidProductSize.Id)))
            .Returns(fetchedProductSize);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            Action actual = () => productSizeService.Update(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Delete_IdNonExisting_ReturnsNull()
        {
            //Arrange
            int         existingId = 12;
            ProductSize expected   = null;

            Mock <IProductSizeRepository> productSizeRepository = new Mock <IProductSizeRepository>();

            productSizeRepository.Setup(repo => repo.Delete(existingId)).
            Returns(expected);
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            ProductSize actual = productSizeService.Delete(existingId);

            //Assert
            Assert.Equal(expected, actual);
        }
        // GET: /ProductMaster/Edit/5

        public ActionResult Edit(int id)
        {
            FinishedProduct          pt = _FinishedProductService.Find(id);
            FinishedProductViewModel vm = AutoMapper.Mapper.Map <FinishedProduct, FinishedProductViewModel>(pt);
            var         pstid           = (int)ProductSizeTypeConstants.StandardSize;
            ProductSize tem             = new ProductSizeService(_unitOfWork).FindProductSize(pstid, pt.ProductId);
            ProductType typ             = new ProductTypeService(_unitOfWork).GetTypeForProduct(id);

            vm.ProductTypeId   = typ.ProductTypeId;
            vm.ProductTypeName = typ.ProductTypeName;
            ViewBag.Sample     = vm.IsSample;
            if (tem != null)
            {
                vm.SizeId = tem.SizeId;
            }
            if (pt == null)
            {
                return(HttpNotFound());
            }
            return(View("Create", vm));
        }
        public void Create_MetricValueNegative_ThrowsArgumentException()
        {
            //Arrange
            ProductSize invalidProductSize = new ProductSize
            {
                ProductMetric = new ProductMetric {
                    Id = 1
                },
                Size         = "XL",
                MetricXValue = 70,
                MetricYValue = -13,
                MetricZValue = 20
            };

            ProductMetric fetchedProductMetric = new ProductMetric
            {
                Id      = 1,
                Name    = "Oversized Hoodie",
                MetricX = "Length",
                MetricY = "Width",
                MetricZ = "Sleeve Length"
            };

            Mock <IProductSizeRepository>   productSizeRepository   = new Mock <IProductSizeRepository>();
            Mock <IProductMetricRepository> productMetricRepository = new Mock <IProductMetricRepository>();

            productMetricRepository.Setup(repo => repo.Read(invalidProductSize.ProductMetric.Id)).
            Returns(fetchedProductMetric);
            IProductSizeService productSizeService = new ProductSizeService(productSizeRepository.Object,
                                                                            productMetricRepository.Object);

            //Act
            Action actual = () => productSizeService.Create(invalidProductSize);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public JsonResult ProductSizesByPaging(DataTablesPaging request)
        {
            var view = new ProductSizeService().GetProductSizesByPaging(request);

            return(Json(view, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Post(FinishedProductViewModel vm)
        {
            if (ModelState.IsValid)
            {
                if (vm.ProductId <= 0)
                {
                    FinishedProduct pt = AutoMapper.Mapper.Map <FinishedProductViewModel, FinishedProduct>(vm);
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.UnitId       = UnitConstants.Pieces;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _FinishedProductService.Create(pt);

                    if (!(vm.SizeId <= 0))
                    {
                        ProductSize ps    = new ProductSize();
                        var         pstid = (int)ProductSizeTypeConstants.StandardSize;
                        ps.SizeId            = vm.SizeId;
                        ps.ProductId         = vm.ProductId;
                        ps.ProductSizeTypeId = pstid;
                        ps.CreatedBy         = User.Identity.Name;
                        ps.ModifiedBy        = User.Identity.Name;
                        ps.CreatedDate       = DateTime.Now;
                        ps.ModifiedDate      = DateTime.Now;
                        new ProductSizeService(_unitOfWork).Create(ps);
                    }
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", vm));
                    }



                    #region

                    //Saving Images if any uploaded after UnitOfWorkSave

                    if (Request.Files[0] != null && Request.Files[0].ContentLength > 0)
                    {
                        //For checking the first time if the folder exists or not-----------------------------
                        string uploadfolder;
                        int    MaxLimit;
                        int.TryParse(ConfigurationManager.AppSettings["MaxFileUploadLimit"], out MaxLimit);
                        var x = (from iid in db.Counter
                                 select iid).FirstOrDefault();
                        if (x == null)
                        {
                            uploadfolder = System.Guid.NewGuid().ToString();
                            Counter img = new Counter();
                            img.ImageFolderName = uploadfolder;
                            img.ModifiedBy      = User.Identity.Name;
                            img.CreatedBy       = User.Identity.Name;
                            img.ModifiedDate    = DateTime.Now;
                            img.CreatedDate     = DateTime.Now;
                            new CounterService(_unitOfWork).Create(img);
                            _unitOfWork.Save();
                        }

                        else
                        {
                            uploadfolder = x.ImageFolderName;
                        }


                        //For checking if the image contents length is greater than 100 then create a new folder------------------------------------

                        if (!Directory.Exists(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)))
                        {
                            Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder));
                        }

                        int count = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)).Length;

                        if (count >= MaxLimit)
                        {
                            uploadfolder = System.Guid.NewGuid().ToString();
                            var u = new CounterService(_unitOfWork).Find(x.CounterId);
                            u.ImageFolderName = uploadfolder;
                            new CounterService(_unitOfWork).Update(u);
                            _unitOfWork.Save();
                        }


                        //Saving Thumbnails images:
                        Dictionary <string, string> versions = new Dictionary <string, string>();

                        //Define the versions to generate
                        versions.Add("_thumb", "maxwidth=100&maxheight=100");  //Crop to square thumbnail
                        versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg

                        string temp2    = "";
                        string filename = System.Guid.NewGuid().ToString();
                        foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys)
                        {
                            HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey];
                            if (pfile.ContentLength <= 0)
                            {
                                continue;                           //Skip unused file controls.
                            }
                            temp2 = Path.GetExtension(pfile.FileName);

                            string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder);
                            if (!Directory.Exists(uploadFolder))
                            {
                                Directory.CreateDirectory(uploadFolder);
                            }

                            string filecontent = Path.Combine(uploadFolder, vm.ProductName + "_" + filename);

                            //pfile.SaveAs(filecontent);
                            ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true));


                            //Generate each version
                            foreach (string suffix in versions.Keys)
                            {
                                if (suffix == "_thumb")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, vm.ProductName + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                                else if (suffix == "_medium")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, vm.ProductName + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                            }

                            //var tempsave = _FinishedProductService.Find(pt.ProductId);

                            pt.ImageFileName   = pt.ProductName + "_" + filename + temp2;
                            pt.ImageFolderName = uploadfolder;
                            pt.ObjectState     = Model.ObjectState.Modified;
                            _FinishedProductService.Update(pt);
                            _unitOfWork.Save();
                        }
                    }

                    #endregion



                    return(RedirectToAction("Create", new { id = vm.ProductTypeId, sample = vm.IsSample }).Success("Data saved successfully"));
                }
                else
                {
                    FinishedProduct temp = _FinishedProductService.Find(vm.ProductId);
                    temp.ProductName             = vm.ProductName;
                    temp.ProductCode             = vm.ProductCode;
                    temp.ProductGroupId          = vm.ProductGroupId;
                    temp.ProductCategoryId       = vm.ProductCategoryId;
                    temp.ProductCollectionId     = vm.ProductCollectionId;
                    temp.SampleId                = vm.SampleId;
                    temp.CounterNo               = vm.CounterNo;
                    temp.ProductQualityId        = vm.ProductQualityId;
                    temp.OriginCountryId         = vm.OriginCountryId;
                    temp.ProductDesignId         = vm.ProductDesignId;
                    temp.ProductInvoiceGroupId   = vm.ProductInvoiceGroupId;
                    temp.ProductDesignPatternId  = vm.ProductDesignPatternId;
                    temp.DrawBackTariffHeadId    = vm.DrawBackTariffHeadId;
                    temp.ProductStyleId          = vm.ProductStyleId;
                    temp.DescriptionOfGoodsId    = vm.DescriptionOfGoodsId;
                    temp.ColourId                = vm.ColourId;
                    temp.StandardCost            = vm.StandardCost;
                    temp.ProductManufacturerId   = vm.ProductManufacturerId;
                    temp.StandardWeight          = vm.StandardWeight;
                    temp.ProcessSequenceHeaderId = vm.ProcessSequenceHeaderId;
                    temp.CBM                  = vm.CBM;
                    temp.ContentId            = vm.ContentId;
                    temp.Tags                 = vm.Tags;
                    temp.FaceContentId        = vm.FaceContentId;
                    temp.ProductSpecification = vm.ProductSpecification;
                    temp.IsActive             = vm.IsActive;

                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _FinishedProductService.Update(temp);

                    if (!(vm.SizeId <= 0))
                    {
                        var         pstid = (int)ProductSizeTypeConstants.StandardSize;;
                        ProductSize ps    = new ProductSizeService(_unitOfWork).FindProductSize(pstid, vm.ProductId);
                        if (ps != null)
                        {
                            ps.SizeId       = vm.SizeId;
                            ps.ProductId    = vm.ProductId;
                            ps.ModifiedDate = DateTime.Now;
                            ps.ModifiedBy   = User.Identity.Name;
                            ps.ObjectState  = Model.ObjectState.Modified;
                            new ProductSizeService(_unitOfWork).Update(ps);
                        }
                        else
                        {
                            ProductSize pss  = new ProductSize();
                            var         psid = (int)ProductSizeTypeConstants.StandardSize;
                            pss.ProductId         = vm.ProductId;
                            pss.SizeId            = vm.SizeId;
                            pss.ProductSizeTypeId = psid;
                            pss.CreatedBy         = User.Identity.Name;
                            pss.ModifiedBy        = User.Identity.Name;
                            pss.CreatedDate       = DateTime.Now;
                            pss.ModifiedDate      = DateTime.Now;
                            new ProductSizeService(_unitOfWork).Create(pss);
                        }
                    }
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", vm));
                    }


                    #region

                    //Saving Image if file is uploaded
                    if (Request.Files[0] != null && Request.Files[0].ContentLength > 0)
                    {
                        string uploadfolder = temp.ImageFolderName;
                        string tempfilename = temp.ImageFileName;
                        if (uploadfolder == null)
                        {
                            var x = (from iid in db.Counter
                                     select iid).FirstOrDefault();
                            if (x == null)
                            {
                                uploadfolder = System.Guid.NewGuid().ToString();
                                Counter img = new Counter();
                                img.ImageFolderName = uploadfolder;
                                img.ModifiedBy      = User.Identity.Name;
                                img.CreatedBy       = User.Identity.Name;
                                img.ModifiedDate    = DateTime.Now;
                                img.CreatedDate     = DateTime.Now;
                                new CounterService(_unitOfWork).Create(img);
                                _unitOfWork.Save();
                            }
                            else
                            {
                                uploadfolder = x.ImageFolderName;
                            }
                        }
                        //Deleting Existing Images

                        var xtemp = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename);
                        if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename)))
                        {
                            System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename));
                        }

                        //Deleting Thumbnail Image:

                        if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename)))
                        {
                            System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename));
                        }

                        //Deleting Medium Image:
                        if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename)))
                        {
                            System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename));
                        }

                        //Saving Thumbnails images:
                        Dictionary <string, string> versions = new Dictionary <string, string>();

                        //Define the versions to generate
                        versions.Add("_thumb", "maxwidth=100&maxheight=100");  //Crop to square thumbnail
                        versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg

                        string temp2    = "";
                        string filename = System.Guid.NewGuid().ToString();
                        foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys)
                        {
                            HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey];
                            if (pfile.ContentLength <= 0)
                            {
                                continue;                           //Skip unused file controls.
                            }
                            temp2 = Path.GetExtension(pfile.FileName);

                            string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder);
                            if (!Directory.Exists(uploadFolder))
                            {
                                Directory.CreateDirectory(uploadFolder);
                            }

                            string filecontent = Path.Combine(uploadFolder, temp.ProductName + "_" + filename);

                            //pfile.SaveAs(filecontent);

                            ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true));

                            //Generate each version
                            foreach (string suffix in versions.Keys)
                            {
                                if (suffix == "_thumb")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, temp.ProductName + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                                else if (suffix == "_medium")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, temp.ProductName + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                            }
                        }
                        var temsave = _FinishedProductService.Find(temp.ProductId);
                        temsave.ImageFileName   = temsave.ProductName + "_" + filename + temp2;
                        temsave.ImageFolderName = uploadfolder;
                        _FinishedProductService.Update(temsave);
                        _unitOfWork.Save();
                    }

                    #endregion



                    return(RedirectToAction("Index", new { id = vm.ProductTypeId, sample = vm.IsSample }).Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var temp = _FinishedProductService.Find(vm.id);

                List <ProductSizeViewModel> sizelist    = new ProductSizeService(_unitOfWork).GetProductSizeForProduct(vm.id).ToList();
                List <ProductProcess>       ProcessList = new ProductProcessService(_unitOfWork).GetProductProcessIdListByProductId(vm.id).ToList();
                List <FinishedProductConsumptionLineViewModel> BOMDetailList = new  BomDetailService(_unitOfWork).GetFinishedProductConsumptionForIndex(vm.id).ToList();
                List <ProductSiteDetail> SiteDetail = new ProductSiteDetailService(_unitOfWork).GetSiteDetailForProduct(vm.id).ToList();


                foreach (var item in sizelist)
                {
                    new ProductSizeService(_unitOfWork).Delete(item.ProductSizeId);
                }

                foreach (var item in ProcessList)
                {
                    new ProductProcessService(_unitOfWork).Delete(item.ProductProcessId);
                }
                foreach (var item in BOMDetailList)
                {
                    new BomDetailService(_unitOfWork).Delete(item.BomDetailId);
                }
                foreach (var item in SiteDetail)
                {
                    new ProductSiteDetailService(_unitOfWork).Delete(item.ProductSiteDetailId);
                }

                ActivityLog al = new ActivityLog()
                {
                    ActivityType = (int)ActivityTypeContants.Deleted,
                    CreatedBy    = User.Identity.Name,
                    CreatedDate  = DateTime.Now,
                    DocId        = vm.id,
                    UserRemark   = vm.Reason,
                    Narration    = "Product is deleted with Name:" + temp.ProductName,
                    DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId,
                    UploadDate   = DateTime.Now,
                };
                new ActivityLogService(_unitOfWork).Create(al);


                _FinishedProductService.Delete(vm.id);

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }


                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Beispiel #15
0
 public WsProductSizeController(CRMContext context)
 {
     _context            = context;
     _productSizeService = new ProductSizeService(_context);
 }
Beispiel #16
0
        public ActionResult OnCreate(ProductModels product)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(product.Code))
                {
                    product.Code = string.Format("{0}-{1}", ConfigHelper.ProductCode, DateTime.Now.Ticks.GetHashCode());
                }
                product.ImageUrl = product.Image != null?
                                   product.Image.Upload() :
                                       product.ImageUrl;

                var newProduct = new Product
                {
                    Name         = product.Name,
                    Type         = product.CategoryId,
                    Summary      = product.Summary,
                    Code         = product.Code,
                    Image        = product.ImageUrl,
                    BrandId      = product.BrandId,
                    Country      = product.Country,
                    Store        = product.Store,
                    Manufacturer = product.ManufacturerId,
                    AccountId    = 0,
                    Number       = product.Number,
                    Unit1        = product.Unit,
                    Weight       = product.Weight,
                    Quantity     = product.Quantity,
                    Npp          = Convert.ToDouble(product.Npp),
                    Width        = product.Width,
                    Height       = product.Height,
                    Depth        = product.Depth,
                    Detail       = product.Detail,
                    WarrantyTime = product.WarrantyTime,
                    ExpireDate   = product.ExpireDate,
                    Title        = product.MetaTitle,
                    Keyword      = product.MetaKeyword,
                    Description  = product.MetaDescription,
                    Price        = product.Price,
                    Transport1   = product.Transport1,
                    Transport2   = product.Transport2,
                    Status       = false
                };
                var result = ProductService.Insert(newProduct);

                //Tao cac anh Slide va properties
                if (product.ProductImages != null && product.ProductImages.Length > 0)
                {
                    ProductImageService.Insert(newProduct.ID, product.Name, product.ProductImages);
                }
                //Tao cac gia tri thuoc tinh
                if (product.AttrLabel != null && product.AttrLabel.Length > 0)
                {
                    ProductAttributeService.Insert(newProduct.ID, product.AttrLabel, product.AttrDesc);
                }
                //Tao saleOff
                if (!string.IsNullOrWhiteSpace(product.Percent))
                {
                    ProductSaleOffService.Insert(new ProductSaleOff
                    {
                        ProductID = newProduct.ID,
                        Percent   = Convert.ToDouble(product.Percent),
                        StartTime = Convert.ToDateTime(product.StartDate),
                        EndTime   = Convert.ToDateTime(product.EndDate)
                    });
                }
                //Tao kich co
                if (product.Size != null && product.Size.Length > 0)
                {
                    ProductSizeService.Insert(newProduct.ID, product.Size);
                }
                //Tao mau sac
                if (product.Color != null && product.Color.Length > 0)
                {
                    ProductColorService.Insert(newProduct.ID, product.Color);
                }
                SetFlashMessage(result == Result.Ok?
                                $"Thêm sản phẩm '{product.Name}' thành công.":
                                "Lỗi khi thêm mới sản phẩm");
                if (product.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListCategory     = BuildListCategory();
                ViewBag.ListBrand        = ProductBrandService.GetAll();
                ViewBag.ListCountry      = CountryService.GetAll();
                ViewBag.ListStore        = ProductStoreService.GetAll();
                ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
                ViewBag.ListUnit         = UnitService.GetAll();
                ViewBag.ListColor        = BuildListColor(product.Color);
                ViewBag.ListSize         = BuildListSize(product.Size);
                ViewBag.ListHour         = DataHelper.ListHour;
                ModelState.Clear();
                return(View("Create", product.ResetValue()));
            }
            ViewBag.ListCategory     = BuildListCategory();
            ViewBag.ListBrand        = ProductBrandService.GetAll();
            ViewBag.ListCountry      = CountryService.GetAll();
            ViewBag.ListStore        = ProductStoreService.GetAll();
            ViewBag.ListManufacturer = ProductManufacturerService.GetAll();
            ViewBag.ListUnit         = UnitService.GetAll();
            ViewBag.ListColor        = BuildListColor(product.Color);
            ViewBag.ListSize         = BuildListSize(product.Size);
            ViewBag.ListHour         = DataHelper.ListHour;

            return(View("Create", product));
        }
        public JsonResult ProductSizes()
        {
            var items = new ProductSizeService().GetProductSizes();

            return(Json(items, JsonRequestBehavior.AllowGet));
        }