Esempio n. 1
0
        public void SetCompareGood(int id)
        {
            GoodDTO good       = goodmanager.Get(id);
            int     categoryId = good.Category_Id;

            ListCompareGoodDTO compgoods = Session["ComparingGoods"] as ListCompareGoodDTO;

            if (compgoods == null)
            {
                compgoods = new ListCompareGoodDTO();

                if (!compgoods.CompareGoods.ContainsKey(categoryId))
                {
                    compgoods.CompareGoods.Add(categoryId, new List <int>());
                }
                compgoods.CompareGoods[categoryId].Add(id);
                Session["ComparingGoods"] = compgoods;
                return;
            }
            else
            {
                if (compgoods.CompareGoods[categoryId].Find(c => c == id) != -1)
                {
                    compgoods.CompareGoods[categoryId].Add(id);
                    Session["ComparingGoods"] = compgoods;
                    return;
                }
            }
        }
Esempio n. 2
0
        public GoodDTO getInforGoods(string maHang)
        {
            GoodDTO goodDTO = new GoodDTO();
            string  sql     = string.Format("SELECT hh.MaHang, hh.TenHang, hh.GiaBanLe, hh.GiabanSi, hh.GiaMua ,  " +
                                            " dvt.Ten, tk.SoLuongToiThieu, hh.TinhChat, kh.TenKho, nh.TenNhom, hh.Active " +
                                            "FROM HANGHOA_DICHVU hh, TONKHO tk, DONVITINH dvt, KHOHANG kh, NHOMHANG nh " +
                                            "WHERE hh.MaDV = dvt.MaDVT and tk.mahang = hh.MaHang and hh.MaKho = kh.MaKho and nh.MaNhom = hh.MaNhom and hh.MaHang = '{0}'", maHang);

            DataTable data = ConnectionDB.getData(sql);

            if (data.Rows.Count > 0)
            {
                goodDTO.MaHang          = data.Rows[0]["MaHang"].ToString();
                goodDTO.TenHang         = data.Rows[0]["TenHang"].ToString();
                goodDTO.GiabanLe        = float.Parse(data.Rows[0]["GiaBanLe"].ToString());
                goodDTO.GiaBanSi        = float.Parse(data.Rows[0]["GiabanSi"].ToString());
                goodDTO.GiaMua          = float.Parse(data.Rows[0]["GiaMua"].ToString());
                goodDTO.TenKho          = data.Rows[0]["TenKho"].ToString();
                goodDTO.SoLuongToiThieu = int.Parse(data.Rows[0]["SoLuongToiThieu"].ToString());
                goodDTO.TinhChat        = data.Rows[0]["TinhChat"].ToString();
                goodDTO.TenDV           = data.Rows[0]["Ten"].ToString();
                goodDTO.TenNhom         = data.Rows[0]["TenNhom"].ToString();
                goodDTO.Active          = bool.Parse(data.Rows[0]["Active"].ToString());
            }
            return(goodDTO);
        }
Esempio n. 3
0
        /// <summary>
        /// Update good into database
        /// </summary>
        /// <param name="good"></param>
        public void Update(GoodDTO good)
        {
            if (good == null)
            {
                return;
            }
            var goodDb = uOW.GoodRepo.GetByID(good.Id);

            if (goodDb == null)
            {
                return;
            }

            var uGood = Mapper.Map <Good>(good);

            goodDb.Name        = uGood.Name;
            goodDb.Category_Id = uGood.Category_Id;
            goodDb.WebShop_Id  = uGood.WebShop_Id;
            goodDb.ImgLink     = uGood.ImgLink;
            goodDb.UrlLink     = uGood.UrlLink;
            goodDb.XmlData     = uGood.XmlData;
            goodDb.Price       = uGood.Price;
            goodDb.Status      = uGood.Status;

            uOW.Save();
        }
Esempio n. 4
0
        public bool Delete(GoodDTO good)
        {
            if (good == null)
            {
                return(false);
            }
            var goodDb = sqlUnitOfWork.GoodRepo.GetByID(good.Id);

            if (goodDb == null)
            {
                return(false);
            }
            goodDb.Status = false;

            try
            {
                var elasticGood = Mapper.Map <GoodDTO>(goodDb);
                elasticUnitOfWork.Repository.Delete(elasticGood);

                if (sqlUnitOfWork.Save() < 1)
                {
                    throw new Exception("Item isn't added into MS SQL Server");
                }
                elasticUnitOfWork.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(false);
            }
            return(true);
        }
        private void InitCommands()
        {
            RemoveGoodCommand = new RelayCommand(x =>
            {
                goodService.Remove(SelectedGood);
                Goods.Remove(SelectedGood);
            });

            RemoveCategoryCommand = new RelayCommand(x =>
            {
                categoryService.Remove(SelectedCategory);
                Categories.Remove(SelectedCategory);
            });

            RemoveManufacturerCommand = new RelayCommand(x =>
            {
                manufacturerService.Remove(SelectedManufactirer);
                Manufacturers.Remove(SelectedManufactirer);
            });

            AddUpdateGoodCommand = new RelayCommand(x =>
            {
                AddUpdateGood dlg = new AddUpdateGood();
                dlg.ShowDialog();
                var good = new GoodDTO
                {
                    GoodName       = GoodViewModelProxy.Proxy.GoodName,
                    GoodCount      = GoodViewModelProxy.Proxy.GoodCount,
                    Price          = GoodViewModelProxy.Proxy.GoodPrice,
                    CategoryId     = categoryService.GetAll().FirstOrDefault(y => y.CategoryName == GoodViewModelProxy.Proxy.GoodCategory).CategoryId,
                    ManufacturerId = manufacturerService.GetAll().FirstOrDefault(y => y.ManufacturerName == GoodViewModelProxy.Proxy.GoodManufacturer).ManufacturerId
                };
                var result = goodService.CreateOrUpdate(good);
                Goods.Add(result);
            });

            AddUpdateCategoryCommand = new RelayCommand(x =>
            {
                AddUpdateCategoryView dlg = new AddUpdateCategoryView();
                dlg.ShowDialog();
                var category = new CategoryDTO
                {
                    CategoryName = CategoryViewModelProxy.Proxy.CategoryName
                };
                var result = categoryService.CreateOrUpdate(category);
                Categories.Add(result);
            });

            AddUpdateManufacturerCommand = new RelayCommand(x =>
            {
                AddUpdateManufactorerView dlg = new AddUpdateManufactorerView();
                dlg.ShowDialog();
                var manufactorer = new ManufacturerDTO
                {
                    ManufacturerName = ManufacturerModelProxy.Proxy.ManufacturerName
                };
                var result = manufacturerService.CreateOrUpdate(manufactorer);
                Manufacturers.Add(result);
            });
        }
Esempio n. 6
0
 public GoodDTO UpdateProd(GoodDTO productToUpdate)
 {
     using (var db = new companyEntities())
     {
         var prod = db.tblGoods.FirstOrDefault(u => u.id == productToUpdate.id);
         return(_mapper.Map <GoodDTO>(prod));
     }
 }
 public ActionResult CreateGoods(GoodDTO goodViewModel)
 {
     if (ModelState.IsValid)
     {
         goodService.CreateOrUpdate(goodViewModel);
         return(RedirectToAction("Index"));
     }
     return(View(goodViewModel));
 }
Esempio n. 8
0
 public async Task <IActionResult> Put([FromBody] GoodDTO good)
 {
     if (ModelState.IsValid)
     {
         Good g = _mapper.Map <Good>(good);
         return(Ok(_mapper.Map <GoodDTO>(await _repository.UpdateGoodAsync(g))));
     }
     return(BadRequest(ModelState));
 }
Esempio n. 9
0
        public int updateGoods(GoodDTO g)
        {
            string sql = string.Format(" update [HANGHOA_DICHVU] " +
                                       " set TenHang = N'{0}', MaDV = N'{1}', GiaMua = {2}, GiaBanSi = {3}, GiaBanLe = {4}, " +
                                       "     SoLuongToiThieu = {5}, MaKho = N'{6}', Active =  '{7}', MaNhom = '{8}', MaNCC = '{9}', TinhChat = N'{10}' " +
                                       " where MaHang = N'{11}' ", g.TenHang, g.MaDonVi, g.GiaMua, g.GiaBanSi, g.GiabanLe, g.SoLuongToiThieu,
                                       g.MaKho, g.Active, g.MaNhom, g.MaNCC, g.TinhChat, g.MaHang);

            return(ConnectionDB.ExcuteNonQuery(sql));
        }
Esempio n. 10
0
 public ActionResult GoodEdit(GoodDTO good)
 {
     if (ModelState.IsValid)
     {
         service.CreateOrUpdate(good);
         service.SaveAll();
         return(RedirectToAction("GoodView"));
     }
     return(RedirectToAction("GoodEdit"));
 }
Esempio n. 11
0
        public ActionResult PhotoList(int id = 1)
        {
            GoodDTO good = goodService.Get(id);

            ViewBag.GoodInfo = $"{good.GoodName}, price - {good.Price} uah";
            ViewBag.GoodId   = id;
            var model = photoService.FindBy(g => g.GoodId == id);

            return(View(model));
        }
Esempio n. 12
0
        //public GoodDTO getInforGoodsFromMaHang(string mahang)
        //{
        //    string sql = string.Format("SELECT * FROM [HANGHOA_DICHVU] where [MaHang] = '{0}'", mahang);
        //    DataTable data = ConnectionDB.getData(sql);
        //    GoodDTO goodDTO = new GoodDTO();

        //    if (data.Rows.Count > 0)
        //    {
        //        goodDTO.MaHang = data.Rows[0]["MaHang"].ToString();
        //        goodDTO.TenHang = data.Rows[0]["TenHang"].ToString();
        //        goodDTO.MaDonVi = data.Rows[0]["MaDV"].ToString();
        //        goodDTO.GiaMua = float.Parse(data.Rows[0]["GiaMua"].ToString());
        //        goodDTO.GiaBanSi = float.Parse(data.Rows[0]["GiabanSi"].ToString());
        //        goodDTO.GiabanLe = float.Parse(data.Rows[0]["GiaBanLe"].ToString());


        //        //goodDTO.TinhChat = "Hàng hóa";
        //        goodDTO.MaKho = data.Rows[0]["MaKho"].ToString();
        //        goodDTO.MaNhom = data.Rows[0]["MaNhom"].ToString();
        //        goodDTO.MaNCC = data.Rows[0]["MaNCC"].ToString();
        //        goodDTO.Active = bool.Parse(data.Rows[0]["Active"].ToString());
        //    }
        //    return goodDTO;
        //}
        public int InsertGood(GoodDTO goodDTO)
        {
            string sql = string.Format("INSERT INTO HANGHOA_DICHVU (MaHang, TenHang, MaDV, GiaMua, " +
                                       "  GiabanLe, GiaBanSi, TinhChat, MaKho, Active, MaNhom, MaNCC, SoLuongToiThieu) values('{0}', N'{1}', '{2}', {3}, {4}," +
                                       " {5}, N'{6}', N'{7}', '{8}', N'{9}', '{10}', {11})", goodDTO.MaHang, goodDTO.TenHang, goodDTO.MaDonVi, goodDTO.GiaMua,
                                       goodDTO.GiabanLe, goodDTO.GiaBanSi, goodDTO.TinhChat, goodDTO.MaKho, goodDTO.Active, goodDTO.MaNhom, goodDTO.MaNCC, goodDTO.SoLuongToiThieu);

            int check = ConnectionDB.ExcuteNonQuery(sql);

            return(check);
        }
Esempio n. 13
0
 public IActionResult Delete([FromBody] GoodDTO good)
 {
     try
     {
         service.Delete(good);
         return(NoContent());
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
Esempio n. 14
0
        private void AddOrder_Click(object sender, RoutedEventArgs e)
        {
            GoodDTO good = new GoodDTO
            {
                Height = Int32.Parse(HeightTextBox.Text), Weight = Int32.Parse(WeightTextBox.Text),
                Width  = Int32.Parse(WidthTextBox.Text), Name = NameTextBox.Text
            };
            GoodService goodService = new GoodService();

            goodService.Create(good);

            MessageBox.Show("Order added");
        }
Esempio n. 15
0
 public Good MapGood(GoodDTO value)
 {
     return(new Good
     {
         Id = value.Id,
         Name = value.Name,
         Price = value.Price,
         Count = value.Count,
         GoodType = MapGoodType(value.GoodType),
         GoodImportance = MapImportance(value.GoodImportance),
         BoughtDate = value.BoughtDate
     });
 }
Esempio n. 16
0
 public HttpResponseMessage Update(GoodDTO good)
 {
     try
     {
         var g = goodService.Update(good);
         return((good != null) ? Request.CreateResponse(HttpStatusCode.OK, good)
            : Request.CreateResponse(HttpStatusCode.BadRequest, $"Не смогли обновить товар с id = {good.GoodId}"));
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Не смогли обновить товар с id = {good.GoodId}"));
     }
 }
Esempio n. 17
0
        public int Create(GoodDTO good)
        {
            var validationResult = validator.Validate(good);

            if (validationResult.IsValid)
            {
                return(repository.Create(mapper.MapGood(good)));
            }
            else
            {
                throw new ValidationException(validationResult.Errors);
            }
        }
Esempio n. 18
0
        public void Update(GoodDTO good)
        {
            var  name     = good.CategoryName;
            var  category = db.Categories.TryGetByName(name);
            Good dbgood   = db.Goods.Get(good.Id);

            dbgood.Name       = good.Name;
            dbgood.CategoryId = category.Id;
            dbgood.Price      = good.Price;
            dbgood.Quantity   = good.Quantity;
            db.Goods.Update(dbgood);
            db.Save();
        }
        public void Put(int id, [FromBody] GoodDTO goodDTO)
        {
            GoodDTO editgood = goodService.Get(id);

            editgood.GoodCount        = goodDTO.GoodCount;
            editgood.GoodName         = goodDTO.GoodName;
            editgood.Price            = goodDTO.Price;
            editgood.ManufacturerId   = goodDTO.ManufacturerId;
            editgood.ManufacturerName = goodDTO.ManufacturerId.HasValue ? manufacturerService.Get(goodDTO.ManufacturerId.Value).ManufacturerName:"";
            editgood.CategoryId       = goodDTO.CategoryId;
            editgood.CategoryName     = goodDTO.CategoryId.HasValue?categoryService.Get(goodDTO.CategoryId.Value).CategoryName:"";
            goodService.CreateOrUpdate(editgood);
        }
Esempio n. 20
0
        public int AddProd(GoodDTO prod)
        {
            if (prod != null)
            {
                using (var db = new companyEntities())
                {
                    db.tblGoods.Add(_mapper.Map <tblGood>(prod));
                    db.SaveChanges();
                    return(prod.id);
                }
            }

            return(0);
        }
Esempio n. 21
0
        private void HardRemove(GoodDTO item)
        {
            if (item == null)
            {
                return;
            }
            var good = GetByIdUrl(item.UrlLink);

            if (good == null)
            {
                return;
            }
            client.Delete <GoodDTO>(good.UrlLink, i => i.Refresh());
        }
Esempio n. 22
0
        /// <summary>
        /// Insert good into database and return inserted item
        /// </summary>
        /// <param name="good"></param>
        /// <returns></returns>
        public GoodDTO Insert(GoodDTO good)
        {
            if (good.ImgLink == null)
            {
                good.ImgLink = @"http://www.kalahandi.info/wp-content/uploads/2016/05/sorry-image-not-available.png";
            }
            var goodDb = Mapper.Map <Good>(good);

            goodDb.Status = true;
            var res = uOW.GoodRepo.Insert(goodDb);

            uOW.Save();
            return(Mapper.Map <GoodDTO>(res));
        }
Esempio n. 23
0
 public HttpResponseMessage Post(GoodDTO good)
 {
     try
     {
         var g = goodService.Add(good);
         HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Accepted, g);
         message.Headers.Add("GoodId", g.GoodId.ToString());
         return(message);
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Не смогли добавить категорию"));
     }
 }
Esempio n. 24
0
        private void Remove(GoodDTO item)
        {
            if (item == null)
            {
                return;
            }
            var good = GetByIdUrl(item.UrlLink);

            if (good == null)
            {
                return;
            }
            good.Status = false;
            Update(good);
        }
Esempio n. 25
0
        private bool Update(GoodDTO item)
        {
            if (item == null)
            {
                return(false);
            }
            var good = GetByIdUrl(item.UrlLink);

            if (good == null)
            {
                return(false);
            }
            client.Index(item, i => i.Id(item.UrlLink).Refresh());
            return(true);
        }
Esempio n. 26
0
        public void Add(GoodDTO good)
        {
            var name     = good.CategoryName;
            var category = db.Categories.TryGetByName(name);

            Good dbgood = new Good();

            //dbgood.Id = good.Id;
            dbgood.Name       = good.Name;
            dbgood.CategoryId = category.Id;
            dbgood.Price      = good.Price;
            dbgood.Quantity   = good.Quantity;
            db.Goods.Add(dbgood);
            db.Save();
        }
Esempio n. 27
0
 public IActionResult Post([FromBody] GoodDTO good)
 {
     try
     {
         return(Ok(service.Create(good)));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Esempio n. 28
0
        /// <summary>
        /// Delete good into database
        /// </summary>
        /// <param name="good"></param>
        public void Delete(GoodDTO good)
        {
            if (good == null)
            {
                return;
            }
            var goodDb = uOW.GoodRepo.GetByID(good.Id);

            if (goodDb == null)
            {
                return;
            }
            goodDb.Status = false;
            uOW.Save();
        }
Esempio n. 29
0
        public ProductForm(IEntityBL entityBL, GoodDTO good)
        {
            InitializeComponent();
            _entityBL = entityBL;
            _good     = good;
            _text     = new List <TextBox>();

            ProductPictureBox.Size     = new Size(120, 150);
            ProductPictureBox.SizeMode = PictureBoxSizeMode.Zoom;
            ProductPictureBox.Image    = Image.FromFile(_good.photo_url);
            NameLabel.Text             = _good.name;
            this.Text         = _good.name;
            DetailsLabel.Text = _good.details;
            _feedBacks        = _entityBL.GetAllFeedBackByProduct(_good.id);
        }
        public void Post([FromBody] GoodDTO goodDTO)
        {
            GoodDTO newGood = new GoodDTO
            {
                GoodCount        = goodDTO.GoodCount,
                GoodName         = goodDTO.GoodName,
                Price            = goodDTO.Price,
                ManufacturerName = goodDTO.ManufacturerName,
                ManufacturerId   = goodDTO.ManufacturerId,
                CategoryName     = goodDTO.CategoryName,
                CategoryId       = goodDTO.CategoryId
            };

            goodService.CreateOrUpdate(newGood);
        }