Ejemplo n.º 1
0
        public async Task <ActionResult> GetProductDetail(string id, string sortBy)
        {
            ProductReviewDTO productReviewDTO = new ProductReviewDTO();

            // Get the product based on the id
            ProductDetailDTO product = await unitOfWork.Products.Get(x => x.Id == id, new ProductDetailDTO());

            // If the product is found in the database, return the product with other product details
            if (product != null)
            {
                var response = new
                {
                    product,
                    media   = await unitOfWork.Media.GetCollection(x => x.ProductId == product.Id, new ProductMediaDTO()),
                    content = await unitOfWork.ProductContent.GetCollection(x => x.ProductId == product.Id, x => new
                    {
                        Type = new {
                            x.ProductContentType.Name,
                            x.ProductContentType.Image
                        },
                        x.Title,
                        PriceIndices = x.PriceIndices.Select(y => y.Index).ToList()
                    }),
                    pricePoints    = await unitOfWork.PricePoints.GetCollection(x => x.ProductId == product.Id, x => string.Format(x.Description, x.Price)),
                    reviews        = await unitOfWork.ProductReviews.GetReviews(product.Id, sortBy, 1),
                    sortOptions    = productReviewDTO.GetSortOptions(),
                    reviewsPerPage = productReviewDTO.GetReviewsPerPage()
                };

                return(Ok(response));
            }

            return(NotFound());
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtProductName.Text))
            {
                MessageBox.Show("Product name is empty");
            }
            else if (cbCategory.SelectedIndex == -1)
            {
                MessageBox.Show("Please select category");
            }
            else if (string.IsNullOrEmpty(txtPrice.Text))
            {
                MessageBox.Show("Price is emtpy");
            }
            else
            {
                var product = new ProductDetailDTO();
                product.Price       = Convert.ToInt32(txtPrice.Text.Trim());
                product.ProductName = txtProductName.Text.Trim();
                product.CategoryID  = Convert.ToInt32(cbCategory.SelectedValue);

                if (bll.Insert(product))
                {
                    MessageBox.Show("Product was added");
                    cbCategory.SelectedIndex = -1;
                    txtPrice.Clear();
                    txtProductName.Clear();
                }
            }
        }
Ejemplo n.º 3
0
 private void FrmSales_Load(object sender, EventArgs e)
 {
     cmbCategory.DataSource    = dto.Categories;
     cmbCategory.DisplayMember = "CategoryName";
     cmbCategory.ValueMember   = "ID";
     cmbCategory.SelectedIndex = -1;
     if (!isUpdate)
     {
         gridProduct.DataSource             = dto.Products;
         gridProduct.Columns[0].HeaderText  = "Product Name";
         gridProduct.Columns[1].HeaderText  = "Category Name";
         gridProduct.Columns[2].HeaderText  = "Stock Amount";
         gridProduct.Columns[3].HeaderText  = "Price";
         gridProduct.Columns[4].Visible     = false;
         gridProduct.Columns[5].Visible     = false;
         gridCustomer.DataSource            = dto.Customers;
         gridCustomer.Columns[0].Visible    = false;
         gridCustomer.Columns[1].HeaderText = "Customer Name";
         if (dto.Categories.Count > 0)
         {
             combofull = true;
         }
     }
     else
     {
         panel1.Hide();
         txtCustomerName.Text       = detail.CustomerName;
         txtProductName.Text        = detail.ProductName;
         txtPrice.Text              = detail.Price.ToString();
         txtProductSalesAmount.Text = detail.SalesAmount.ToString();
         ProductDetailDTO product = dto.Products.First(x => x.ProductID == detail.ProductID);
         detail.StockAmount = product.StockAmount;
         txtStock.Text      = detail.StockAmount.ToString();
     }
 }
Ejemplo n.º 4
0
 private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
 {
     detail             = new ProductDetailDTO();
     detail.ProductID   = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[4].Value);
     detail.CategoryID  = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
     detail.ProductName = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
     detail.Price       = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[3].Value);
 }
        public async Task <ActionResult> Edit([Bind(Include = "id,Name,ProductNumber,Color,StandardCost,ListPrice,Size,Weight,SellStartDate,SellEndDate,DiscontinuedDate,ThumbnailPhotoFileName,ModifiedDate,Type")] ProductDetailDTO productDetailDTO)
        {
            if (ModelState.IsValid)
            {
                await Client.UpsertDocumentAsync("/dbs/AdventureWorksLT/colls/documents", productDetailDTO);

                return(RedirectToAction("Index"));
            }
            return(View(productDetailDTO));
        }
Ejemplo n.º 6
0
 //Set data từ List dạng ProductDetailDTO vào dgv_ProductData
 //Ném value vào datagridview
 public void BindGrid(int index, ProductDetailDTO item)
 {
     dgv_ProductData.Rows[index].Cells[0].Value = index;
     dgv_ProductData.Columns[0].HeaderText      = "STT";
     //dgv_ProductData.Rows[index].Cells[1].Value = item.ProductID;//lưu ProductID vào cell[0]
     dgv_ProductData.Rows[index].Cells[1].Value = item.ProductTypeID;     //Lưu ProductTypeID vào cell[1]
     dgv_ProductData.Rows[index].Cells[2].Value = item.SellPrice;         //Lưu SellPrice vào cell[2]
     dgv_ProductData.Rows[index].Cells[3].Value = item.BuyPrice;          //Lưu BuyPrice vào cell[3]
     dgv_ProductData.Rows[index].Cells[4].Value = item.DateOfManufacture; //Lưu DateOfManufacture vào cell[4]
     dgv_ProductData.Rows[index].Cells[5].Value = item.ExpiryDate;        //Lưu ExpiryDate vào cell[5]
     dgv_ProductData.Rows[index].Cells[6].Value = item.Note;              //Lưu Note vào cell[6]
 }
Ejemplo n.º 7
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (txtProductName.Text.Trim() == "")
     {
         MessageBox.Show("Product Name is Empty");
     }
     else if (cmbCategory.SelectedIndex == -1)
     {
         MessageBox.Show("Please select a category");
     }
     else if (txtPrice.Text.Trim() == "")
     {
         MessageBox.Show("Price is empty");
     }
     else
     {
         if (!isUpdate)//Add
         {
             ProductDetailDTO product = new ProductDetailDTO();
             product.ProductName = txtProductName.Text;
             product.CategoryID  = Convert.ToInt32(cmbCategory.SelectedValue);
             product.Price       = Convert.ToInt32(txtPrice.Text);
             if (bll.Insert(product))
             {
                 MessageBox.Show("Product was added");
                 txtPrice.Clear();
                 txtProductName.Clear();
                 cmbCategory.SelectedIndex = -1;
             }
         }
         else
         {
             if (detail.ProductName == txtProductName.Text &&
                 detail.CategoryID == Convert.ToInt32(cmbCategory.SelectedValue) &&
                 detail.Price == Convert.ToInt32(txtPrice.Text))
             {
                 MessageBox.Show("There is no change");
             }
             else
             {
                 detail.ProductName = txtProductName.Text;
                 detail.CategoryID  = Convert.ToInt32(cmbCategory.SelectedValue);
                 detail.Price       = Convert.ToInt32(txtPrice.Text);
                 if (bll.Update(detail))
                 {
                     MessageBox.Show("Product wa Updated");
                     this.Close();
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
        public bool UpdateDTO(string productId, ProductDetailDTO productDetailDTO)
        {
            if (DataHelper.IsEmptyString(productId))
            {
                return(false);
            }
            var detailId = DataHelper.GetDetailId(productId);
            var prod     = ObjectMapperTo <ProductDetailDTO, ProductDetail>(productDetailDTO);
            PropModified <ProductDetail> modified = new PropModified <ProductDetail>(prod);

            using (EntityDAO <ProductDetail> db = new EntityDAO <ProductDetail>(_context))
                return(db.Update(detailId, modified));
        }
Ejemplo n.º 9
0
        public async Task <ProductDetailDTO> InsertAsync(ProductDetailDTO obj, CancellationToken token = default(CancellationToken))
        {
            if (obj.ImageBytes == null || obj.ImageBytes.Length == 0)
            {
                throw new ArgumentException("Image cannot be empty.");
            }
            Product toInsert = Mapper.Map <Product>(obj);

            toInsert.ImageID = (await imageManager.InsertBytesAsync(obj.ImageBytes)).ID;
            Product inserted = await serviceProvider.GetService <IProductRepository>().InsertAsync(toInsert);

            return(await FindByIDAsync(inserted.ID));
        }
        public ActionResult UpdateProductDetail(string id, ProductDetailDTO productDetailDTO)
        {
            if (!ModelState.IsValid || DataHelper.IsEmptyString(id))
            {
                return(BadRequest());
            }
            //
            var re = _productModel.UpdateDTO(id, productDetailDTO);

            if (!re)
            {
                return(Problem(statusCode: 500, detail: "Can't update data"));
            }
            _cache.DataUpdated(CacheKey.PRODUCT);
            return(Ok());
        }
Ejemplo n.º 11
0
        //display detail of the product..
        public ProductDetailDTO GetProductDetail(ProductDetailDTO productDetailDTO)
        {
            try
            {
                bool exists = ProductDBObject.ProductExists(productDetailDTO.Name);
            }
            catch (NotFoundException ex)
            {
                throw new ProductDoesNotExists();
            }
            catch (Exception ex)
            {
                throw new Exception("Unknown Error");
            }
            ProductDetailDTO produDetailDTO = ProductDBObject.GetDetail(productDetailDTO);

            return(produDetailDTO);
        }
Ejemplo n.º 12
0
        public JsonResult ProductDetailList(int idFarm)
        {
            var dao = new FarmerOfferDao();
            var productDetaillist = dao.ProductDetailList(idFarm);

            List <ProductDetailDTO> productDTOs = new List <ProductDetailDTO>();

            foreach (var item in productDetaillist)
            {
                ProductDetailDTO productDetail = new ProductDetailDTO();
                productDetail.id          = item.Id_ProductDetail;
                productDetail.productName = item.PRODUCT.Name_Product;
                productDetail.seedname    = item.SEED.Name_Seed;
                productDetail.cropName    = item.Name_Crop;
                productDTOs.Add(productDetail);
            }

            return(Json(new { data = productDTOs }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 13
0
        public async Task <ProductDetailDTO> UpdateAsync(ProductDetailDTO obj, CancellationToken token = default(CancellationToken))
        {
            Product old = (await serviceProvider.GetService <IProductRepository>()
                           .LoadWith(p => p.Image)
                           .FindByIDAsync(obj.ID));
            Product toUpd = Mapper.Map <Product>(obj);

            if (obj.ImageBytes != null && obj.ImageBytes.Length != 0)
            {
                toUpd.ImageID = (await imageManager.UpdateBytesAsync(obj.ImageBytes, old.Image.Path, token)).ID;
            }
            else
            {
                toUpd.ImageID = old.ImageID;
            }
            await serviceProvider.GetService <IProductRepository>().UpdateAsync(toUpd, token);

            return(await FindByIDAsync(toUpd.ID));
        }
Ejemplo n.º 14
0
        public ActionResult PDetail([Bind(Include = "Name")] ProductDetail productDetail)
        {
            ProductDetailDTO prodDetailDTO = new ProductDetailDTO();

            try
            {
                ProductDetailDTO productDetailDTO = productmapper.Map <ProductDetail, ProductDetailDTO>(productDetail);
                prodDetailDTO = productDetailContext.GetProductDetail(productDetailDTO);
            }
            catch (CategoryDoesNotExists ex)
            {
                return(View("Error" + ex));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex + ":Exception occured");
            }
            ProductDetail p = productmapper.Map <ProductDetailDTO, ProductDetail>(prodDetailDTO);

            return(View(p));
        }
Ejemplo n.º 15
0
        public SqlParameter[] CreateAllParameterDTO(ProductDetailDTO data)
        {
            SqlParameter ParID = new SqlParameter("@ProductID", System.Data.SqlDbType.NVarChar);                    //tạo Parameter lưu ProductID

            ParID.Value = data.ProductID;                                                                           // lưu value cell[0] dạng string

            SqlParameter ParProductTypeID = new SqlParameter("@ProductTypeID", System.Data.SqlDbType.NVarChar);     //tạo Parameter lưu ProductTypeID

            ParProductTypeID.Value = data.ProductTypeID;                                                            // lưu value cell[1] dạng string

            SqlParameter ParSellPrice = new SqlParameter("@SellPrice", System.Data.SqlDbType.Decimal);              //tạo Parameter lưu SellPrice

            ParSellPrice.Value = data.SellPrice;                                                                    // lưu value cell[2] dạng double được convert từ dạng string

            SqlParameter ParBuyPrice = new SqlParameter("@BuyPrice", System.Data.SqlDbType.Decimal);                //tạo Parameter lưu BuyPrice

            ParBuyPrice.Value = data.BuyPrice;                                                                      // lưu value cell[3] dạng double được convert từ dạng string

            SqlParameter ParDateOfManufacture = new SqlParameter("@DateOfManufacture", System.Data.SqlDbType.Date); //tạo Parameter lưu DateOfManufacture

            ParDateOfManufacture.Value = Convert.ToDateTime(data.DateOfManufacture).ToShortDateString().ToString(); // lưu value cell[4] dạng date được convert từ dạng datetime nhưng chỉ lọc ra ngày tháng năm

            SqlParameter ParExpiryDate = new SqlParameter("@ExpiryDate", System.Data.SqlDbType.Date);               //tạo Parameter lưu ExpiryDate

            ParExpiryDate.Value = Convert.ToDateTime(data.ExpiryDate).ToShortDateString().ToString();               // lưu value cell[5] dạng date được convert từ dạng datetime nhưng chỉ lọc ra ngày tháng năm

            SqlParameter ParNote = new SqlParameter("@Note", System.Data.SqlDbType.NVarChar);                       //tạo Parameter lưu Note

            if (data.Note == null)                                                                                  //Nếu cell này null thì trả về chuỗi rỗng
            {
                ParNote.Value = "";
            }
            else
            {
                ParNote.Value = data.Note;// lưu value cell[6] dạng string
            }

            SqlParameter[] Pars = { ParID, ParProductTypeID, ParSellPrice, ParBuyPrice, ParDateOfManufacture, ParExpiryDate, ParNote };
            return(Pars);
        }
Ejemplo n.º 16
0
        // public bool UpdateForOrder(List<OrderDetailDTO> orderDetailDTOs)
        // {
        //     using (ProductDAO db = new ProductDAO(_context))
        //     {
        //         foreach (var item in orderDetailDTOs)
        //         {
        //             int itemId = DataHelper.GetAttrlId(item.ProductId);
        //             db.SubTractQuanity(itemId, (int)item.Quantity);
        //         }
        //     }
        //     return true;
        // }


        //Product Detail
        public ProductDetailDTO AddDTOs(int cateId, ProductDetailDTO productDetailDTO)
        {
            if (cateId <= 0)
            {
                return(null);
            }
            var prod = ObjectMapperTo <ProductDetailDTO, ProductDetail>(productDetailDTO);

            prod.CategoryId = cateId;
            using (EntityDAO <ProductDetail> db = new EntityDAO <ProductDetail>(_context))
            {
                var result = ObjectMapperTo <ProductDetail, ProductDetailDTO>(db.Add(prod));
                if (result == null)
                {
                    return(null);
                }
                this.AddAttrDTOs(result.Id, new ProductDTO {
                    Name = "Unknown", Color = "N/A", Images = "[]"
                });
                return(result);
            }
        }
        public ActionResult <String> AddProductDetail(int cateId, ProductDetailDTO productDetailDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            //
            var modified = new PropModified <ProductDetailDTO>(productDetailDTO);

            if (!modified.isChanged || cateId <= 0)
            {
                return(BadRequest());
            }
            var re = _productModel.AddDTOs(cateId, productDetailDTO);

            if (re == null)
            {
                return(Problem(statusCode: 500, detail: "Can't add data"));
            }
            _cache.DataUpdated(CacheKey.PRODUCT);
            return(Ok(re.Id));
        }
Ejemplo n.º 18
0
        //Method
        //Trả về một list chứa toàn bộ data của ProductDetail
        public List <ProductDetailDTO> GetProductDetailToList()
        {
            string sql = "Select * from ProductDetail";                                // thực hiện lấy toàn bộ thông tin từ table ProductDetail
            List <ProductDetailDTO> ListProductDetail = new List <ProductDetailDTO>(); // khai báo obj đầu ra

            SqlDataReader Reader = ReadData(sql);                                      // thực hiện lấy data từ database đưa vào biến reader

            while (Reader.Read())                                                      //vòng lặp đến khi không còn row nào có thể đọc trong databse
            {
                ProductDetailDTO data = new ProductDetailDTO();                        // tạo 1 obj tên data chứa thông tin của 1 dòng data
                data.ProductID         = Reader["ProductID"].ToString();
                data.ProductTypeID     = Reader["ProductTypeID"].ToString();
                data.SellPrice         = double.Parse(Reader["SellPrice"].ToString());
                data.BuyPrice          = double.Parse(Reader["BuyPrice"].ToString());
                data.DateOfManufacture = convertDate(Reader["DateOfManufacture"]);
                data.ExpiryDate        = convertDate(Reader["ExpiryDate"]);
                data.Note = Reader["Note"].ToString();

                ListProductDetail.Add(data); // Add vào list
            }
            CloseConnection();               // đóng data lại
            return(ListProductDetail);       //trả về list chứa toàn bộ data trong table ProductDetail
        }
Ejemplo n.º 19
0
 private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
 {
     if (cmbDeletedData.SelectedIndex == 0)
     {
         categorydetail              = new CategoryDetailDTO();
         categorydetail.ID           = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
         categorydetail.CategoryName = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
     }
     else if (cmbDeletedData.SelectedIndex == 1)
     {
         customerdetail              = new CustomerDetailDTO();
         customerdetail.ID           = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
         customerdetail.CustomerName = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
     }
     else if (cmbDeletedData.SelectedIndex == 2)
     {
         productdetail                   = new ProductDetailDTO();
         productdetail.ProductID         = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[4].Value);
         productdetail.CategoryID        = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
         productdetail.ProductName       = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
         productdetail.Price             = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[3].Value);
         productdetail.isCategoryDeleted = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[6].Value);
     }
     else
     {
         salesdetail                   = new SalesDetailDTO();
         salesdetail.SalesID           = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[10].Value);
         salesdetail.ProductID         = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[4].Value);
         salesdetail.CustomerName      = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
         salesdetail.ProductName       = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
         salesdetail.Price             = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value);
         salesdetail.SalesAmount       = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[6].Value);
         salesdetail.isCategoryDeleted = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[11].Value);
         salesdetail.isCustomerDeleted = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[12].Value);
         salesdetail.isProductDeleted  = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[13].Value);
     }
 }
Ejemplo n.º 20
0
        //function to get the details of the product using name of the product
        public ProductDetailDTO GetDetail(ProductDetailDTO productDetailDTO)
        {
            Product  product  = dbContext.Product.Where(a => a.Name == productDetailDTO.Name).FirstOrDefault();
            Category category = dbContext.Category.Where(ab => ab.ID == product.CategoryID).FirstOrDefault();

            dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
            if (product != null)
            {
                ProductDetailDTO newBasicDTO = new ProductDetailDTO();
                newBasicDTO.Name        = product.Name;
                newBasicDTO.ID          = product.ID;
                newBasicDTO.Description = product.Description;
                newBasicDTO.CatName     = category.Name;
                newBasicDTO.Variants    = (from v in dbContext.Variant.Where(cdf => cdf.ProductID == product.ID)
                                           join vp in dbContext.VariantProperty on v.ID equals vp.VariantID
                                           join img in dbContext.VariantImage on v.ID equals img.VariantID
                                           join vpv in dbContext.VariantPropertyValue on vp.PropertyValueID equals vpv.ID
                                           join p in dbContext.Property on vpv.PropertyID equals p.ID
                                           join value in dbContext.Value on vpv.ValueID equals value.ID
                                           select new VariantDTO()
                {
                    VariantId = v.ID,
                    ListingPrice = v.ListingPrice,
                    Discount = v.Discount,
                    Variant_Property = p.Name,
                    Variant_Value1 = value.Name,
                    image = img.ImageURL
                });
                Variant      var = dbContext.Variant.Where(cdf => cdf.ProductID == product.ID).FirstOrDefault();
                VariantImage ima = dbContext.VariantImage.Where(cd => cd.VariantID == var.ID).First();
                newBasicDTO.ImageURL     = ima.ImageURL;
                newBasicDTO.ListingPrice = var.ListingPrice;
                newBasicDTO.Discount     = var.Discount;
                return(newBasicDTO);
            }
            return(null);
        }
Ejemplo n.º 21
0
 public async Task <ProductDetailDTO> Add(ProductDetailDTO item)
 {
     return(await ServiceProvider.GetService <IProductManager>().InsertAsync(item));
 }
Ejemplo n.º 22
0
 public void UpdateAsync(ProductDetailDTO obj, CancellationToken token = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
 public void Update(ProductDetailDTO obj)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 24
0
 public Task <ProductDetailDTO> InsertAsync(ProductDetailDTO obj, CancellationToken token = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
 public ProductDetailDTO Insert(ProductDetailDTO obj)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 26
0
 public async Task <ProductDetailDTO> Update(ProductDetailDTO item)
 {
     return(await ServiceProvider.GetService <IProductManager>().UpdateAsync(item));
 }
Ejemplo n.º 27
0
        //adding product to the cart using the loggedin user's userID
        public bool AddProduct(Guid id, Guid user_id)
        {
            Product product = dbContext.Product.Where(a => a.ID == id).FirstOrDefault();

            if (product == null)
            {
                dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                Variant variant = dbContext.Variant.Where(s => s.ID == id).FirstOrDefault();

                Guid               p_id    = variant.ProductID;
                Product            pr      = dbContext.Product.Where(cdd => cdd.ID == p_id).FirstOrDefault();
                VariantImage       vimage  = dbContext.VariantImage.Where(cdd => cdd.VariantID == variant.ID).FirstOrDefault();
                ProductDetailDTO   cartdto = new ProductDetailDTO();
                IEnumerable <Cart> ca      = dbContext.Cart.Where(pd => pd.UserID == user_id);
                foreach (var cd in ca)
                {
                    if (cd.VariantID == variant.ID)
                    {
                        return(false);
                    }
                }

                Cart cart = new Cart();
                cart.ID           = Guid.NewGuid();
                cart.VariantID    = variant.ID;
                cart.SellingPrice = variant.Discount;
                cart.Qty          = 1;
                cart.UserID       = user_id;
                cartdto.Name      = pr.Name;
                cartdto.ImageURL  = vimage.ImageURL;
                dbContext.Cart.Add(cart);
                dbContext.SaveChanges();
                return(true);
            }
            else
            {
                dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                Variant variant = dbContext.Variant.Where(s => s.ProductID == id).FirstOrDefault();
                //Guid p_id = variant.ProductID;
                VariantImage       vimage  = dbContext.VariantImage.Where(cdd => cdd.VariantID == variant.ID).FirstOrDefault();
                ProductDetailDTO   cartdto = new ProductDetailDTO();
                IEnumerable <Cart> ca      = dbContext.Cart.Where(pd => pd.UserID == user_id);
                foreach (var cd in ca)
                {
                    if (cd.VariantID == variant.ID)
                    {
                        return(false);
                    }
                }
                Cart cart = new Cart();
                cart.ID           = Guid.NewGuid();
                cart.VariantID    = variant.ID;
                cart.SellingPrice = variant.Discount;
                cart.Qty          = 2;
                cart.UserID       = user_id;
                cartdto.Name      = product.Name;
                cartdto.ImageURL  = vimage.ImageURL;
                dbContext.Cart.Add(cart);
                dbContext.SaveChanges();
                return(true);
            }
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Post(string productName, [FromBody] ProductDetailDTO detail)
        {
            await _productDetailService.AddAsync(productName, detail.Name, detail.Value);

            return(Created($"products/{productName}/details/", null));
        }
Ejemplo n.º 29
0
        //H
        public IActionResult UpdateProduct()
        {
            if (!IsAdmin())
            {
                return(View(index));
            }
            bool       check        = false;
            string     productIDStr = Request.Form["txtProductID"];
            int        productID    = Int32.Parse(productIDStr);
            string     priceStr     = Request.Form["txtProductPrice"];
            double     price        = Double.Parse(priceStr);
            string     color        = Request.Form["txtProductColor"];
            ProductDTO proDto       = new ProductDTO
            {
                ProductId = productID,
                Color     = color,
                Price     = price
            };

            if (check = new ProductData().UpdateProductById(proDto))
            {
                string[] size                = Request.Form["txtSize"];
                string[] quantity            = Request.Form["txtQuantity"];
                List <ProductDetailDTO> list = new List <ProductDetailDTO>();
                ProductDetailDTO        detailDto;
                for (int i = 0; i < size.Length; i++)
                {
                    detailDto = new ProductDetailDTO
                    {
                        ProductId = productID,
                        Quantity  = Int32.Parse(quantity[i]),
                        Size      = Int32.Parse(size[i])
                    };
                    list.Add(detailDto);
                }
                if (check = new ProductDetailData().UpdateQuantityByProductDTO(list))
                {
                    string[] newSize     = Request.Form["txtNewSize"];
                    string[] newQuantity = Request.Form["txtNewQuantity"];
                    if (newSize != null && newQuantity != null)
                    {
                        List <ProductDetailDTO> newList = new List <ProductDetailDTO>();
                        ProductDetailDTO        newDetailDto;
                        for (int i = 0; i < newSize.Length; i++)
                        {
                            newDetailDto = new ProductDetailDTO
                            {
                                ProductId = productID,
                                Quantity  = Int32.Parse(newQuantity[i]),
                                Size      = Int32.Parse(newSize[i])
                            };
                            newList.Add(newDetailDto);
                        }
                        check = new ProductDetailData().AddProductDetailsByProductDTO(newList);
                    }
                }
            }
            if (check)
            {
                ViewBag.Successful = "Update successfully!";
            }
            else
            {
                ViewBag.Failed = "Update failed!";
            }

            return(View("ProductManager"));
        }