コード例 #1
0
        public ProductDomainModel GetProductForEdit(int productID)
        {
            ProductDomainModel model = new ProductDomainModel();

            if (productID > 0)
            {
                Product product = productRepository.SingleOrDefault(x => x.ProductID == productID);

                model.ProductID         = product.ProductID;
                model.ProductName       = product.ProductName;
                model.ProductCategoryID = product.ProductCategoryID;
                model.Description       = product.Description;
                model.Price             = product.Price;
                model.ImageID           = product.ImageID;
                model.ImagePath         = product.ProductImage.ImagePath;
                model.ImageSize         = product.ProductImage.ImageSize;
                model.ImageHeight       = product.ProductImage.ImageHeight;
                model.ImageWidth        = product.ProductImage.ImageWidth;
                model.RoastLevelID      = product.RoastLevelID;
                model.EquipmentTypeID   = product.EquipmentTypeID;
                model.DrinkwareTypeID   = product.DrinkwareTypeID;
            }

            return(model);
        }
コード例 #2
0
        public async Task <string> AddUpdateUser(ProductVM productVM)
        {
            ProductDomainModel productDM = new ProductDomainModel();

            AutoMapper.Mapper.Map(productVM, productDM);
            return(await productBusiness.AddUpdateProduct(productDM));
        }
コード例 #3
0
        public async Task <ProductToReturnVM> GetProductById(int id)
        {
            ProductToReturnVM  productToReturnVM  = new ProductToReturnVM();
            ProductDomainModel productDomainModel = await productBusiness.GetProductById(id);

            AutoMapper.Mapper.Map(productDomainModel, productToReturnVM);
            return(productToReturnVM);
        }
コード例 #4
0
        public async Task <ProductToReturnVM> GetProductByBarcode(string barcode)
        {
            ProductToReturnVM  productToReturnVM  = new ProductToReturnVM();
            ProductDomainModel productDomainModel = await productBusiness.GetProductByBarcode(barcode);

            AutoMapper.Mapper.Map(productDomainModel, productToReturnVM);
            return(productToReturnVM);
        }
コード例 #5
0
 /// <summary>
 /// Convert From ProductDomainModel To Product
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static Product Map(ProductDomainModel obj)
 {
     return(new Product
     {
         ProductID = obj.ProductID,
         ProductName = obj.ProductName,
         UnitPrice = obj.UnitPrice
     });
 }
コード例 #6
0
        public ActionResult ViewProduct(int productID)
        {
            ProductDomainModel productDM = productsBusiness.GetProduct(productID);

            ProductViewModel productVM = new ProductViewModel();

            AutoMapper.Mapper.Map(productDM, productVM);

            return(PartialView("_ViewProduct", productVM));
        }
コード例 #7
0
        public bool Delete(int id)
        {
            ProductDomainModel productToDelete = Date.Products.FirstOrDefault(x => x.Id == id);

            if (productToDelete != null)
            {
                Date.Products.Remove(productToDelete);
                return(true);
            }
            return(false);
        }
コード例 #8
0
        public ActionResult EditProduct(int productId)
        {
            ProductDomainModel products = product.Get(productId);

            var viewModel = Mapper.Map <EditProductViewModel>(products);
            IEnumerable <CategoryDomainModel> categories = category.Get();

            viewModel.Categories = Mapper.Map <List <CategoryViewModel> >(categories);

            return(View(viewModel));
        }
コード例 #9
0
        public async Task <string> AddUpdateProduct(ProductDomainModel product)
        {
            string status = "";

            if (product.pro_id > 0)
            {
                tblProduct productToUpdate = await productRepository.SingleOrDefault(e => e.pro_id == product.pro_id);

                if (productToUpdate != null)
                {
                    productToUpdate.name           = product.name;
                    productToUpdate.barcode        = product.barcode;
                    productToUpdate.description    = product.description;
                    productToUpdate.purchase_price = product.purchase_price;
                    productToUpdate.sell_price     = product.sell_price;
                    productToUpdate.fsubCat_id     = product.fsubCat_id;
                    productToUpdate.quantity       = product.quantity;
                    productToUpdate.mainCat_id     = product.mainCat_id;
                    productToUpdate.cat_id         = product.cat_id;
                    productToUpdate.subCat_id      = product.subCat_id;

                    await productRepository.Update(productToUpdate);

                    status = "updated";
                }
            }
            else
            {
                tblProduct productToAdd = new tblProduct();
                productToAdd.name           = product.name;
                productToAdd.barcode        = product.barcode;
                productToAdd.description    = product.description;
                productToAdd.purchase_price = product.purchase_price;
                productToAdd.sell_price     = product.sell_price;
                productToAdd.fsubCat_id     = product.fsubCat_id;
                productToAdd.quantity       = product.quantity;
                productToAdd.mainCat_id     = product.mainCat_id;
                productToAdd.cat_id         = product.cat_id;
                productToAdd.subCat_id      = product.subCat_id;

                await productRepository.Insert(productToAdd);

                status = "added";
            }
            return(status);
        }
コード例 #10
0
        public void UpdateProduct(ProductViewModel productVM)
        {
            if (productVM.ImageFile != null)
            {
                string filePath        = string.Empty;
                string fileContentType = string.Empty;

                byte[] uploadedFile = new byte[productVM.ImageFile.InputStream.Length];
                productVM.ImageFile.InputStream.Read(uploadedFile, 0, uploadedFile.Length);

                fileContentType = productVM.ImageFile.ContentType;
                string folderPath = "/ProductsImage/";
                string fileName   = DateTime.Now.ToString("yyyyMMddHHmmss-") + productVM.ImageFile.FileName;

                this.WriteBytesToFile(this.Server.MapPath(folderPath), uploadedFile, fileName);
                filePath = folderPath + fileName;

                string fullFilePath = "C:/Users/Jairus Macatangay/source/repos/CaffeineFix/CaffeineFix" + filePath;

                FileInfo fi      = new FileInfo(fullFilePath);
                string   imgSize = (fi.Length / 1024) + " KB";

                Bitmap bitmap    = new Bitmap(fullFilePath);
                int    imgHeight = bitmap.Height;
                int    imgWidth  = bitmap.Width;

                ProductImageDomainModel img = new ProductImageDomainModel();

                img.ImageName   = fileName;
                img.ImageByte   = uploadedFile;
                img.ImageID     = (int)productVM.ImageID;
                img.ImagePath   = filePath;
                img.ImageExt    = fileContentType;
                img.IsDeleted   = false;
                img.ImageSize   = imgSize;
                img.ImageHeight = imgHeight;
                img.ImageWidth  = imgWidth;

                productsBusiness.SaveImageData(img);
            }

            ProductDomainModel productDM = new ProductDomainModel();

            AutoMapper.Mapper.Map(productVM, productDM);
            productsBusiness.UpdateProduct(productDM);
        }
コード例 #11
0
        public bool Update(ProductDomainModel model)
        {
            ProductDomainModel oldProduct = Date.Products.FirstOrDefault(x => x.Id == model.Id);

            if (oldProduct != null)
            {
                CategoryDomainModel category = Data.Date.Categories.FirstOrDefault(x => x.Id == model.CategoryId);
                if (category == null)
                {
                    return(false);
                }
                oldProduct.Category = category;
                oldProduct.Name     = model.Name;
                oldProduct.Price    = model.Price;
                return(true);
            }
            return(false);
        }
コード例 #12
0
        public ProductDomainModel GetProduct(int productID)
        {
            Product product = productRepository.SingleOrDefault(x => x.ProductID == productID);

            ProductDomainModel dm = new ProductDomainModel();

            dm.ProductID           = product.ProductID;
            dm.ProductName         = product.ProductName;
            dm.Description         = product.Description;
            dm.Price               = product.Price;
            dm.ProductCategoryName = product.ProductCategory.ProductCategoryName;
            dm.RoastLevelLabel     = product.RoastLevel.RoastLevelLabel;
            dm.EquipmentTypeLabel  = product.EquipmentType.EquipmentTypeLabel;
            dm.DrinkwareTypeLabel  = product.DrinkwareType.DrinkwareTypeLabel;
            dm.ImagePath           = product.ProductImage.ImagePath;

            return(dm);
        }
コード例 #13
0
        public ViewResult Index(int page = 1)
        {
            ProductDomainModel    domainProduct = new ProductDomainModel();
            ProductsListViewModel model         = new ProductsListViewModel
            {
                Products = domainProduct.GetAll()
                           .OrderBy(x => x.Sku)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = domainProduct.GetAll().Count()
                }
            };

            return(View(model));
        }
コード例 #14
0
        public ViewResult ShowByCategory(string category, int page = 1)
        {
            ProductDomainModel    p     = new ProductDomainModel();
            ProductsListViewModel model = new ProductsListViewModel
            {
                Products = p.GetByCategory(category)
                           .OrderBy(x => x.Sku)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = p.GetByCategory(category).Count()
                }
            };

            return(View(model));
        }
コード例 #15
0
        public ActionResult LoadEditProductForm(int productID)
        {
            List <ProductCategoryDomainModel> categoryList      = productsBusiness.GetCategories();
            List <RoastLevelDomainModel>      roastLevelList    = productsBusiness.GetRoastLevelList(1);
            List <EquipmentTypeDomainModel>   equipmentTypeList = productsBusiness.GetEquipmentTypesList(1);
            List <DrinkwareTypeDomainModel>   drinkwareTypeList = productsBusiness.GetDrinkwareTypesList(1);

            ViewBag.CategoryList      = new SelectList(categoryList, "ProductCategoryID", "ProductCategoryName");
            ViewBag.RoastLevelList    = new SelectList(roastLevelList, "RoastLevelID", "RoastLevelLabel");
            ViewBag.EquipmentTypeList = new SelectList(equipmentTypeList, "EquipmentTypeID", "EquipmentTypeLabel");
            ViewBag.DrinkwareTypeList = new SelectList(drinkwareTypeList, "DrinkwareTypeID", "DrinkwareTypeLabel");

            ProductDomainModel productDM = productsBusiness.GetProductForEdit(productID);

            ProductViewModel productVM = new ProductViewModel();

            AutoMapper.Mapper.Map(productDM, productVM);

            return(PartialView("_EditProductForm", productVM));
        }
コード例 #16
0
        public void AddProduct(ProductDomainModel productDM)
        {
            Product product = new Product();

            product.ProductName       = productDM.ProductName;
            product.ProductCategoryID = productDM.ProductCategoryID;
            product.Description       = productDM.Description;
            product.ImageID           = productDM.ImageID;
            product.Price             = productDM.Price;

            if (productDM.RoastLevelID != null)
            {
                product.RoastLevelID = productDM.RoastLevelID;
            }
            else
            {
                product.RoastLevelID = 0;
            }

            if (productDM.EquipmentTypeID != null)
            {
                product.EquipmentTypeID = productDM.EquipmentTypeID;
            }
            else
            {
                product.EquipmentTypeID = 0;
            }

            if (productDM.DrinkwareTypeID != null)
            {
                product.DrinkwareTypeID = productDM.DrinkwareTypeID;
            }
            else
            {
                product.DrinkwareTypeID = 0;
            }

            product.DateCreated = DateTime.Now;
            product.IsDeleted   = false;
            productRepository.Insert(product);
        }
コード例 #17
0
        public async Task <ProductDomainModel> GetProductByBarcode(string barcode)
        {
            ProductDomainModel product = new ProductDomainModel();
            var model = await productRepository.SingleOrDefault(p => p.barcode == barcode);

            if (model != null)
            {
                product.pro_id         = model.pro_id;
                product.name           = model.name;
                product.barcode        = model.barcode;
                product.description    = model.description;
                product.purchase_price = model.purchase_price;
                product.sell_price     = model.sell_price;
                product.fsubCat_id     = model.fsubCat_id;
                product.quantity       = model.quantity;
                product.mainCat_id     = model.mainCat_id;
                product.cat_id         = model.cat_id;
                product.subCat_id      = model.subCat_id;
            }
            return(product);
        }
コード例 #18
0
        public void UpdateProduct(ProductDomainModel productDM)
        {
            Product product = productRepository.SingleOrDefault(x => x.ProductID == productDM.ProductID);

            product.ProductName       = productDM.ProductName;
            product.ProductCategoryID = productDM.ProductCategoryID;
            product.Description       = productDM.Description;
            product.ImageID           = productDM.ImageID;
            product.Price             = productDM.Price;

            if (productDM.RoastLevelID != null)
            {
                product.RoastLevelID = productDM.RoastLevelID;
            }
            else
            {
                product.RoastLevelID = 0;
            }

            if (productDM.EquipmentTypeID != null)
            {
                product.EquipmentTypeID = productDM.EquipmentTypeID;
            }
            else
            {
                product.EquipmentTypeID = 0;
            }

            if (productDM.DrinkwareTypeID != null)
            {
                product.DrinkwareTypeID = productDM.DrinkwareTypeID;
            }
            else
            {
                product.DrinkwareTypeID = 0;
            }

            product.DateLastModified = DateTime.Now;
            productRepository.Update(product);
        }
コード例 #19
0
        public void AddProduct(ProductViewModel productVM)
        {
            int imageID = 0;

            if (productVM.ImageFile != null)
            {
                string filePath        = string.Empty;
                string fileContentType = string.Empty;

                byte[] uploadedFile = new byte[productVM.ImageFile.InputStream.Length];
                productVM.ImageFile.InputStream.Read(uploadedFile, 0, uploadedFile.Length);

                fileContentType = productVM.ImageFile.ContentType;
                string folderPath = "/ProductsImage/";
                string fileName   = DateTime.Now.ToString("yyyyMMddHHmmss-") + productVM.ImageFile.FileName;

                this.WriteBytesToFile(this.Server.MapPath(folderPath), uploadedFile, fileName);
                filePath = folderPath + fileName;

                string fullFilePath = "C:/Users/Jairus Macatangay/source/repos/CaffeineFix/CaffeineFix" + filePath;

                FileInfo fi      = new FileInfo(fullFilePath);
                string   imgSize = (fi.Length / 1024) + " KB";

                int      fiAttempts = 0;
                int      fiTimes    = 3;
                TimeSpan fiDelay    = TimeSpan.FromSeconds(5.0);
                int      imgHeight  = 0;
                int      imgWidth   = 0;

                do
                {
                    try
                    {
                        fiAttempts++;
                        using (Bitmap bitmap = new Bitmap(fullFilePath))
                        {
                            imgHeight = bitmap.Height;
                            imgWidth  = bitmap.Width;
                        }
                        break;
                    }
                    catch (Exception ex)
                    {
                        if (fiAttempts == fiTimes)
                        {
                            throw ex;
                        }
                        Task.Delay(fiDelay).Wait();
                    }
                } while (true);

                ProductImageDomainModel img = new ProductImageDomainModel();

                img.ImageName   = fileName;
                img.ImageByte   = uploadedFile;
                img.ImagePath   = filePath;
                img.ImageExt    = fileContentType;
                img.IsDeleted   = false;
                img.ImageSize   = imgSize;
                img.ImageHeight = imgHeight;
                img.ImageWidth  = imgWidth;

                productsBusiness.SaveImageData(img);

                imageID = productsBusiness.GetRecentImageID();
            }

            productVM.ImageID = imageID;

            ProductDomainModel productDM = new ProductDomainModel();

            AutoMapper.Mapper.Map(productVM, productDM);
            productsBusiness.AddProduct(productDM);
        }
コード例 #20
0
        public ProductDomainModel Get(int productId)
        {
            ProductDomainModel product = Date.Products.FirstOrDefault(x => x.Id == productId);

            return(product);
        }
コード例 #21
0
        public ViewResult Show(string id)
        {
            ProductDomainModel p = new ProductDomainModel();

            return(View(p.GetBySku(id)));
        }