Beispiel #1
0
        public async Task Import(ImportProductDto product)
        {
            await _mediator.Send(new ImportProductCommand()
            {
                ProductCount = product.ProductCount
            });

            await _messageHubContext.Clients.All.SendAsync("ReceiveMessage", $"New products added.");
        }
Beispiel #2
0
        public string ImportProduct(ImportProductDto importInformation, DateTime dateCreate)
        {
            try
            {
                using (var dbContext = new XeNangEntities())
                {
                    dbContext.NhapHangs.Add(new NhapHang()
                    {
                        NgayNhapHang = dateCreate,
                        ID_Product   = importInformation.ID_Product,
                        SoLuong      = importInformation.Quantities,
                        TinhTrang    = importInformation.Status,
                        Hang         = importInformation.Label,
                        PhanLoaiXe   = importInformation.Classification,
                        MoTa         = importInformation.Description,
                        Loai         = importInformation.Category,
                        ID           = (from s in dbContext.NhapHangs select s.ID).Count() + 1
                    });

                    var thisProductInStock = dbContext.Khoes.Where(p => p.ID == importInformation.ID_Product)
                                             .DefaultIfEmpty(null)
                                             .FirstOrDefault();
                    if (thisProductInStock == null)
                    {
                        dbContext.Khoes.Add(new Kho()
                        {
                            ID          = importInformation.ID_Product,
                            NgayUpdated = dateCreate,
                            SoLuong     = importInformation.Quantities
                        });
                    }
                    else
                    {
                        thisProductInStock.SoLuong += importInformation.Quantities;
                    }

                    dbContext.SaveChanges();

                    return(Constant.MESSAGE_SUCCESS);
                }
            }
            // CATCH EXEPTION FOR DEBUG PURPOSE
            catch (DbEntityValidationException ex)
            {
                foreach (var e in ex.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      e.Entry.Entity.GetType().Name, e.Entry.State);
                    foreach (var ve in e.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(Constant.MESSAGE_ERROR);
            }
            catch (DbUpdateException ex)
            {
                return(Constant.MESSAGE_ERROR);
            }
        }
 private void btn_Them_Click(object sender, EventArgs e)
 {
     try
     {
         ImportProductDto pro = new ImportProductDto();
         ProductService   sv  = new ProductService();
         if (string.IsNullOrEmpty(cbb_Loai.Text))
         {
             MessageBox.Show("Vui lòng chọn loại sản phẩm !!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             cbb_Loai.Focus();
         }
         else if (string.IsNullOrEmpty(tb_TenSanPham.Text))
         {
             MessageBox.Show("Vui lòng chọn loại sản phẩm !!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             tb_TenSanPham.Focus();
         }
         else if (string.IsNullOrEmpty(dtp_NgayNhapHang.Text))
         {
             MessageBox.Show("Vui lòng chọn ngày nhập hàng!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             dtp_NgayNhapHang.Focus();
         }
         else if (string.IsNullOrEmpty(tb_SoLuong.Text))
         {
             MessageBox.Show("Vui lòng nhập số lượng sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             tb_SoLuong.Focus();
         }
         else if (string.IsNullOrEmpty(cbb_TinhTrang.Text))
         {
             MessageBox.Show("Vui lòng chọn tình trạng sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             cbb_TinhTrang.Focus();
         }
         else if (string.IsNullOrEmpty(tb_Hang.Text))
         {
             MessageBox.Show("Vui lòng nhập hãng sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             tb_Hang.Focus();
         }
         else if (string.IsNullOrEmpty(tb_MoTa.Text))
         {
             MessageBox.Show("Vui lòng nhập mô tả sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             tb_MoTa.Focus();
         }
         else if (string.IsNullOrEmpty(cbb_PhanLoai.Text))
         {
             MessageBox.Show("Vui lòng chọn phân loại sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             cbb_PhanLoai.Focus();
         }
         else
         {
             DateTime NgayNhap = dtp_NgayNhapHang.Value;
             int      SoLuong  = Int32.Parse(tb_SoLuong.Text.ToString());
             pro.Category       = Loai;
             pro.Status         = TinhTrang;
             pro.Classification = PhanLoai;
             pro.ProductName    = tb_TenSanPham.Text.ToString();
             pro.ID_Product     = Helper.GetIDFromName(tb_TenSanPham.Text.ToString());
             pro.Label          = tb_Hang.Text.ToString();
             pro.Description    = tb_MoTa.Text.ToString();
             pro.Quantities     = SoLuong;
             DialogResult dlg = MessageBox.Show("Xác nhận thông tin nhập hàng đã chính xác!!", "Thông báo!!", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
             if (dlg.Equals(DialogResult.OK))
             {
                 sv.ImportProduct(pro, NgayNhap);
                 fillData();
                 MessageBox.Show("Đã thêm thông tin nhập hàng!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 HelperUI.ResetAllControls(groupBox1);
             }
         }
     }
     catch
     {
         //MessageBox.Show("..");
     }
 }
Beispiel #4
0
 public void ImportProduct(ImportProductDto importInformation, DateTime dateCreate)
 {
     _repository.ImportProduct(importInformation, dateCreate);
 }
Beispiel #5
0
        public IActionResult ImportProduct([FromBody] ImportProductDto product)
        {
            var jobId = BackgroundJob.Enqueue(() => _importJobHelper.Import(product));

            return(Ok($"Job Id {jobId} for Import Completed."));
        }