예제 #1
0
        public IActionResult Create([FromBody] ProductDO product)
        {
            var productDo = new ProductDO
            {
                ProductNumber = product.ProductNumber,
                ProductName   = product.ProductName,
                Price         = product.Price
            };

            try
            {
                var insertedProduct = false;

                return(Json(new
                {
                    code = "success",
                    data = insertedProduct
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    code = "fail",
                    message = ex.Message
                }));
            }
        }
예제 #2
0
 public ProductDO Insert(ProductDO product)
 {
     _context.Set <ProductDO>().Add(product);
     _context.SaveChanges();
     return
         (product);
 }
        public ActionResult Product_Read([DataSourceRequest] DataSourceRequest request)
        {
            using (var db = new ProjectWebEntities())
            {
                var result = new List <ProductDO>();
                foreach (var m in db.Tbl_Product.OrderByDescending(m => m.DateCreate).ToList())
                {
                    var tmp = new ProductDO
                    {
                        Id          = m.Id,
                        ProductType = m.Tbl_ProductType.Name,
                        ImagePath   = m.ImagePath,
                        Code        = m.Code,
                        Name        = m.Name,
                        Price       = string.Format(CultureInfo.CreateSpecificCulture("el-GR"), "{0:0,0} đ", m.RealPrice),
                        DateCreate  = m.DateCreate,
                        IsDisable   = m.IsDisable,
                        IsHot       = m.IsHot,
                        //IsStatus = m.IsStatus
                    };

                    result.Add(tmp);
                }
                return(Json(result.ToDataSourceResult(request)));
            }
        }
예제 #4
0
        public ActionResult ProductDetail(Guid productId)
        {
            var pdo         = new ProductDO();
            var productInfo = pdo.GetProductInfo(productId);

            return(View(productInfo));
        }
예제 #5
0
        public IActionResult Create([FromBody] ProductVO product)
        {
            var productDO = new ProductDO
            {
                ProductNumber = product.ProductNumber,
                ProductName   = product.ProductName,
                Price         = Convert.ToDouble(product.Price),
                Price         = product.Price
            };

            try
            {
                var insertedProduct = _productService.Insert(productDO);

                return(Json(new
                {
                    code = "success",
                    data = insertedProduct
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    code = "fail",
                    message = ex.Message
                }));
            }
        }
예제 #6
0
 public IActionResult Update([FromBody] ProductVO product)
 {
     try
     {
         var productDO = new ProductDO
         {
             Id            = product.Id,
             ProductNumber = product.ProductNumber,
             ProductName   = product.ProductName,
             ProductType   = product.ProductType,
             Price         = Convert.ToDouble(product.Price)
         };
         _productService.Update(productDO);
         return(Json(new
         {
             code = "success",
         }));
     }
     catch (Exception ex)
     {
         return(Json(new
         {
             code = "fail",
             message = ex.Message
         }));
     }
 }
예제 #7
0
        public Result <ProductDO> Update(string CacheKey, ProductDO model)
        {
            Result <ProductDO> result;

            try
            {
                var updateEntity = _productService.Get(w => w.Id == model.Id);
                updateEntity.IsActive    = model.IsActive;
                updateEntity.CategoryId  = model.CategoryId;
                updateEntity.Description = model.Description;
                updateEntity.ImageUrl    = model.ImageUrl;
                updateEntity.Name        = model.Name;
                updateEntity.Price       = model.Price;
                updateEntity.UpdateTime  = DateTime.Now;


                _productService.Update(updateEntity);

                result = new Result <ProductDO>(model);
            }
            catch (Exception ex)
            {
                result = new Result <ProductDO>(false, ResultTypeEnum.Error, "An error occured during the updating product operation! Ex:" + ex.ToString());
            }
            return(result);
        }
예제 #8
0
        public IHttpActionResult Get()
        {
            var pdo  = new ProductDO();
            var data = pdo.GetProductAllInfoList();

            return(Ok(data));
        }
예제 #9
0
        // GET: Product/Edit/5
        public ActionResult Edit(int id)
        {
            ProductManagement productManagement = new ProductManagement();
            ProductDO         modelData         = productManagement.GetProductByID(id);

            ProductEditViewModel model = new ProductEditViewModel();

            model.Product_ID   = modelData.Product_ID;
            model.Product_Name = modelData.Product_Name;
            model.Price        = modelData.Price;

            // model.Category_ID = modelData.Category_ID;
            model.Categories = GetCategoryDropdownData();

            model.SubCategory_ID = modelData.SubCategory_ID;
            model.SubCategories  = getSubCategoryDropDownData();

            model.Brand_ID = modelData.Brand_ID;
            model.Brands   = getBrandDropDownData();

            model.Size          = modelData.Size;
            model.Color         = modelData.Color;
            model.Product_Image = modelData.Product_Image;
            model.Description   = modelData.Description;
            model.Quantity      = modelData.Quantity;

            TempData["ImagesPath"] = model.Product_Image;

            return(View(model));
        }
예제 #10
0
        public ActionResult UpdateProduct(int productID)
        {
            ProductDO item = null;
            ProductPO display = null;
            ActionResult response = RedirectToAction("Index", "Home");

            //Available to all roles
            if (Session["RoleID"] != null)
            {
                try
                {
                    item = _dataAccess.ReadIndividualProduct(productID);
                    display = ProductMappers.ProductDOtoPO(item);
                }

                catch (Exception exception)
                {
                    ErrorLogger.LogExceptions(exception);
                    response = View(productID);
                }

                finally
                { }

                response = View(display);
            }

            else
            {
                response = RedirectToAction("Index", "Home");
            }

            return response;
        }
예제 #11
0
        public void Add(Product itemToAdd)
        {
            ProductDO dataToAdd = new ProductDO();

            dbContext.Add <ProductDO>(dataToAdd);
            dbContext.SaveChanges();
        }
예제 #12
0
 public int AddProduct(ProductDO product)
 {
     // Check if product of same name exists
     if (db.Products.ToList().Exists(p => p.ProductName.ToLower() == product.ProductName.ToLower()))
     {
         return(db.Products.FirstOrDefault(p => p.ProductName.ToLower() == product.ProductName.ToLower()).ProductId);
     }
     db.Products.Add(product);
     db.SaveChanges();
     return(product.ProductId);
 }
        public IActionResult ProductDetail(string easyUrl, int id)
        {
            ProductDO          model         = new ProductDO();
            Result <ProductDO> productResult = _productBL.GetById(id);

            if (productResult.IsSuccess)
            {
                model = productResult.Data;
            }
            return(View(model));
        }
예제 #14
0
        public virtual Product Get(int id)
        {
            Product   product   = null;
            ProductDO productDO = _DataContext.Product_Get(id).SingleOrDefault();

            if (productDO != null)
            {
                product.ProductID = productDO.ProductID;
            }
            return(product);
        }
예제 #15
0
        // GET: Product/Details/5
        public ActionResult Details(int id)
        {
            ProductManagement       productManagement = new ProductManagement();
            ProductDO               model             = productManagement.GetProductByID(id);
            ProductDetailsViewModel details           = new ProductDetailsViewModel();

            details.Product_ID    = model.Product_ID;
            details.Product_Name  = model.Product_Name;
            details.Product_Image = model.Product_Image;
            details.Description   = model.Description;
            return(View(details));
        }
        public static ProductPO ProductDOtoPO(ProductDO input)
        {
            ProductPO output = new ProductPO();

            output.ProductID       = input.ProductID;
            output.Name            = input.Name;
            output.TypeOfEquipment = input.TypeOfEquipment;
            output.Manufacturer    = input.Manufacturer;
            output.ModelYear       = input.ModelYear;

            return(output);
        }
        private static ProductDO ProductTranslateDatabaseRowToItemInObject(DataRow databaseInput)
        {
            ProductDO output = new ProductDO();

            output.ProductID       = (int)databaseInput["ProductID"];
            output.Name            = databaseInput["Name"].ToString();
            output.TypeOfEquipment = databaseInput["TypeOfEquipment"].ToString();
            output.Manufacturer    = databaseInput["Manufacturer"].ToString();
            output.ModelYear       = (int)databaseInput["ModelYear"];

            return(output);
        }
예제 #18
0
        public ActionResult Edit(int id, ProductEditViewModel model, HttpPostedFileBase ImageFile)
        {
            try
            {
                // TODO: Add update logic here
                ProductDO dataModel = new ProductDO();
                dataModel.Product_ID   = model.Product_ID;
                dataModel.Product_Name = model.Product_Name;
                dataModel.Price        = model.Price;
                //dataModel.Category_ID = model.Category_ID;
                dataModel.SubCategory_ID = model.SubCategory_ID;
                dataModel.Brand_ID       = model.Brand_ID;
                dataModel.Size           = model.Size;
                dataModel.Color          = model.Color;


                if (ImageFile == model.ImageFile)
                {
                    dataModel.Product_Image = TempData["ImagesPath"].ToString();
                    //dataModel.Product_Image = model.Product_Image;
                    dataModel.Description = model.Description;
                    dataModel.Quantity    = model.Quantity;

                    ProductManagement productManagement = new ProductManagement();
                    productManagement.EditProduct(dataModel);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    string FileName   = Path.GetFileName(model.ImageFile.FileName);
                    string UploadPath = ConfigurationManager.AppSettings["ImagesPath"].ToString();
                    model.Product_Image = UploadPath + FileName;
                    model.ImageFile.SaveAs(Server.MapPath((model.Product_Image)));
                    dataModel.Product_Image = model.Product_Image;
                    dataModel.Description   = model.Description;
                    dataModel.Quantity      = model.Quantity;

                    ProductManagement productManagement = new ProductManagement();
                    productManagement.EditProduct(dataModel);

                    return(RedirectToAction("Index"));
                }
                //dataModel.Product_Image = model.Product_Image;
            }
            catch (Exception e)
            {
                model.SubCategories = getSubCategoryDropDownData();
                model.Brands        = getBrandDropDownData();
                return(View(model));
            }
        }
예제 #19
0
        public ProductDO Update(ProductDO product)
        {
            var productExists = _context.Set <ProductDO>().Any(t => t.Id == product.Id);

            if (!productExists)
            {
                throw new Exception("没有找到指定ID的产品记录");
            }

            _context.Set <ProductDO>().Update(product);
            _context.SaveChanges();
            return(product);
        }
예제 #20
0
        public ActionResult ContentTable(string typeOfContent)
        {
            if (!typeOfContent.Equals(MenuItem.MESSAGE.ToString()))
            {
                List <CategoryDO> Categories = CategoryDO.GetCategory(typeOfContent);
                ViewBag.Products = ProductDO.GetProducts(Categories);

                return(PartialView("_PartialTableContent"));
            }
            else
            {
                return(PartialView("Contact"));
            }
        }
예제 #21
0
        internal bool SaveNewProduct()
        {
            try
            {
                var _combinedPath = ProductFileProvider.GetFileData().Path;
                List <IIdentifiable> _allProductsIds = new List <IIdentifiable>();
                //stworzenie nowego obiektu produktu
                ProductDO _product = new ProductDO
                {
                    ProductName     = View.ProductName,
                    Carbo           = View.Carbo,
                    Fat             = View.Fat,
                    KcalPer100Gramm = View.KcalPerGramm,
                    Salt            = View.Salt,
                    Whey            = View.Whey,
                    Id = 1
                };
                var _serializedProduct = JsonConvert.SerializeObject(_product);
                if (!ProductFileProvider.CheckIfFileExists())
                {
                    using (var _file = File.CreateText(_combinedPath))
                    {
                        _file.WriteLine("[");
                        _file.WriteLine(_serializedProduct);
                        _file.WriteLine("]");
                        _file.Close();
                    }
                }
                else
                {
                    var _allFile          = File.ReadAllText(_combinedPath);
                    var _deserializedFile = JsonConvert.DeserializeObject <List <Identifiable> >(_allFile);

                    var _tempFilePath = Path.GetTempFileName();
                    var _linesToKeep  = File.ReadLines(_combinedPath).Where(x => x != "]").ToList();
                    _product.Id = _deserializedFile.Select(x => x.Id).Max() + 1;
                    var _lastIndexOfProductList = _linesToKeep.Count - 1;
                    _linesToKeep[_lastIndexOfProductList] = string.Format("{0},", _linesToKeep[_lastIndexOfProductList]);
                    _linesToKeep.Add(JsonConvert.SerializeObject(_product));
                    _linesToKeep.Add("]");
                    File.WriteAllLines(_tempFilePath, _linesToKeep);
                    File.Delete(_combinedPath);
                    File.Move(_tempFilePath, _combinedPath);
                }

                return(true);
            }
            catch { return(false); }
        }
예제 #22
0
        public static ProductDO ReaderToProduct(SqlDataReader from)
        {
            ProductDO to = new ProductDO();

            to.Name            = from["ProductName"] as string;
            to.CategoryName    = from["CategoryName"] as string;
            to.QuantityPerUnit = from["QuantityPerUnit"] as string;
            to.UnitPrice       = Math.Round((decimal)from["UnitPrice"], 2);
            to.UnitsInStock    = (Int16)from["UnitsInStock"];
            to.UnitsOnOrder    = (Int16)from["UnitsOnOrder"];
            to.ReorderLevel    = (Int16)from["ReorderLevel"];
            to.Discontinued    = (bool)from["Discontinued"];

            return(to);
        }
예제 #23
0
        public static ProductPO MapDoToPo(ProductDO from)
        {
            ProductPO to = new ProductPO();

            to.Name            = from.Name;
            to.CategoryName    = from.CategoryName;
            to.QuantityPerUnit = from.QuantityPerUnit;
            to.UnitPrice       = from.UnitPrice;
            to.UnitsInStock    = from.UnitsInStock;
            to.UnitsOnOrder    = from.UnitsOnOrder;
            to.ReorderLevel    = from.ReorderLevel;
            to.Discontinued    = from.Discontinued;

            return(to);
        }
        public virtual Product Get(int id)
        {
            Product   product   = null;
            ProductDO productDO = _DataContext.spProduct_Get(id).SingleOrDefault();

            if (productDO != null)
            {
                product                    = new Product();
                product.ProductID          = productDO.ProductID;
                product.ProductCode        = productDO.ProductCode;
                product.ProductName        = productDO.ProductName;
                product.ProductVersion     = productDO.ProductVersion;
                product.ProductReleaseDate = productDO.ProductReleaseDate;
            }
            return(product);
        }
예제 #25
0
        public Result <ProductDO> GetById(int id)
        {
            Result <ProductDO> result;

            try
            {
                Product   product   = _productService.GetAsQueryable(w => w.Id == id).FirstOrDefault();
                ProductDO productDO = Mapper.Map <Product, ProductDO>(product);
                result = new Result <ProductDO>(productDO);
            }
            catch (Exception ex)
            {
                result = new Result <ProductDO>(false, ResultTypeEnum.Error, "An error occured when getting Product ! Ex:", ex.Message);
            }
            return(result);
        }
예제 #26
0
        public static ProductPO DOToPO(ProductDO from)
        {
            ProductPO to = new ProductPO();

            to.ProductId       = from.ProductId;
            to.ProductName     = from.ProductName;
            to.SupplierId      = from.SupplierId;
            to.CatagoryId      = from.CatagoryId;
            to.QuantityPerUnit = from.QuantityPerUnit;
            to.UnitPrice       = from.UnitPrice;
            to.UnitsInStock    = from.UnitsInStock;
            to.UnitsOnOrder    = from.UnitsOnOrder;
            to.ReorderLevel    = from.ReorderLevel;
            to.Discontinued    = from.Discontinued;

            return(to);
        }
        //READ INDIVIDUAL PRODUCT BY ID
        public ProductDO ReadIndividualProduct(int ProductID)
        {
            ProductDO     productDataObject            = new ProductDO();
            SqlConnection connection                   = null;
            SqlCommand    readIndividualProductCommand = null;
            SqlDataReader reader = null;

            try
            {
                connection = new SqlConnection(_connectionString);
                readIndividualProductCommand             = new SqlCommand("READ_INDIVIDUAL_PRODUCT_BY_ID", connection);
                readIndividualProductCommand.CommandType = CommandType.StoredProcedure;

                connection.Open();

                readIndividualProductCommand.Parameters.AddWithValue("ProductID", ProductID);

                reader = readIndividualProductCommand.ExecuteReader();
                reader.Read();

                productDataObject.ProductID       = (int)reader["ProductID"];
                productDataObject.Name            = reader["Name"].ToString();
                productDataObject.TypeOfEquipment = reader["TypeOfEquipment"].ToString();
                productDataObject.Manufacturer    = reader["Manufacturer"].ToString();
                productDataObject.ModelYear       = (int)reader["ModelYear"];

                reader.Close();
            }

            catch (Exception exception)
            {
                ErrorLogger.LogExceptions(exception);
                throw exception;
            }

            finally
            {
                if (connection != null)
                {
                    connection.Close();
                    connection.Dispose();
                }
            }

            return(productDataObject);
        }
예제 #28
0
        public static ProductDO ReaderToProduct(SqlDataReader from)
        {
            ProductDO to = new ProductDO();

            to.ProductId       = from.GetInt32(0);
            to.ProductName     = from.GetValue(1) as string;
            to.SupplierId      = from.GetInt32(2);
            to.CatagoryId      = from.GetInt32(3);
            to.QuantityPerUnit = from.GetValue(4) as string;
            to.UnitPrice       = from.GetDecimal(5);
            to.UnitsInStock    = from.GetInt16(6);
            to.UnitsOnOrder    = from.GetInt16(7);
            to.ReorderLevel    = from.GetInt16(8);
            to.Discontinued    = from.GetBoolean(9);

            return(to);
        }
예제 #29
0
        public static List <ProductDO> MapPOtoDO(List <ProductPO> fromPO)
        {
            List <ProductDO> toDO = new List <ProductDO>();

            try
            {
                foreach (ProductPO data in fromPO)
                {
                    ProductDO mappedData = MapPOtoDO(data);
                    toDO.Add(mappedData);
                }
            }
            catch (Exception)
            {
            }
            return(toDO);
        }
예제 #30
0
        public static ProductPO MapDOtoPO(ProductDO fromDO)
        {
            ProductPO toPO = new ProductPO();

            try
            {
                toPO.ProductName     = fromDO.ProductName;
                toPO.QuantityPerUnit = fromDO.QuantityPerUnit;
                toPO.UnitPrice       = fromDO.UnitPrice;
                toPO.UnitsInStock    = fromDO.UnitsInStock;
                toPO.UnitsOnOrder    = fromDO.UnitsOnOrder;
            }
            catch (Exception)
            {
            }
            return(toPO);
        }