Ejemplo n.º 1
0
        public ActionResult Edit(GoodViewModel viewModel, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            var good = new Good
            {
                GoodId         = viewModel.GoodId,
                CategoryId     = viewModel.CategoryId,
                ManufacturerId = viewModel.ManufacturerId,
                GoodCount      = viewModel.GoodCount,
                GoodName       = viewModel.GoodName,
                Price          = viewModel.Price
            };

            foreach (var photo in fileUpload)
            {
                if (photo == null)
                {
                    break;
                }

                string path       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploaded/");
                string filename   = Path.GetFileName(photo.FileName);
                string pathToFile = Path.Combine(path, filename);
                if (filename != null)
                {
                    photo.SaveAs(pathToFile);
                }

                _photoRepository.AddOrUpdate(new Photo {
                    GoodId = viewModel.GoodId, PhotoPath = pathToFile
                });
            }

            _goodRepository.AddOrUpdate(good);
            return(RedirectToAction("Index", "Good"));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id = 0)
        {
            var t = repo.GetAll().FirstOrDefault(x => x.GoodId == id);

            goodModel = new GoodViewModel(t);
            return(View(goodModel));
        }
Ejemplo n.º 3
0
        public ActionResult EditPost(GoodViewModel goodViewModel)
        {
            var good = new Good();

            if (goodViewModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            good = _goodRepository.Get(x => x.Id == goodViewModel.GoodId).FirstOrDefault();

            if (!TryUpdateModel(good, "",
                                new string[] { "Name", "Price", "Description", "Manufacturer_ID", "Type_ID", "Amount" }))
            {
                return(View(good));
            }
            try
            {
                _goodRepository.Save();
                return(RedirectToAction("ControlPanel"));
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }
            return(View(good));
        }
Ejemplo n.º 4
0
 public void Post([FromBody] GoodViewModel value)
 {
     if (value != null)
     {
         _goodsRepository.AddOrUpdate(value);
     }
 }
        public async Task <IActionResult> Edit(int id)
        {
            var good = await db.GetByIdAsync(id);


            if (good != null)
            {
                GoodViewModel gv = new GoodViewModel()
                {
                    Good = good
                };
                return(View(gv));
            }

            //if (goodWM.UploadedFile != null)
            //{

            //string path = "/Files" + good.FileName;
            //using (FileStream file = new FileStream(environment.WebRootPath + path, FileMode.Create))
            //{
            //    await good.CopyToAsync(file);
            //}
            //Good good = new Good();
            //good = goodWM.Good;
            //good.FileName = goodWM.UploadedFile.FileName;
            //good.Path = path;
            //await db.AddAsync(good);

            return(RedirectToAction("Index"));
            //}
        }
Ejemplo n.º 6
0
        public ActionResult Edit(string id)
        {
            Good          good          = new Good();
            GoodViewModel goodViewModel = new GoodViewModel();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            good = _goodRepository.Get(x => x.Id == id).FirstOrDefault();

            if (good == null)
            {
                return(HttpNotFound());
            }

            goodViewModel.GoodId         = good.Id;
            goodViewModel.Name           = good.Name;
            goodViewModel.Price          = good.Price;
            goodViewModel.ManufacturerId = good.ManufacturerId;
            goodViewModel.Amount         = good.Amount;
            goodViewModel.TypeId         = good.TypeId;
            goodViewModel.Description    = good.Description;
            goodViewModel.ManufacturerVM = _manufacturerRepository.Get();
            goodViewModel.TypeVM         = _typeRepository.Get();

            return(View(goodViewModel));
        }
Ejemplo n.º 7
0
 public ActionResult GoodByCategory(int id = 0, int pageNum = 1)
 {
     goodModel          = new GoodViewModel();
     goodModel.AllGoods = repoGood.GetAll().Where(x => x.CategoryId == id).ToList();
     ViewBag.AllGood    = goodModel.AllGoods.Count();
     goodModel.AllGoods = goodModel.AllGoods.Skip(perPage * (pageNum - 1)).Take(perPage).ToList();
     return(View(goodModel));
 }
Ejemplo n.º 8
0
        public ActionResult Edit(int id = 0)
        {
            goodIdForSavingImage = id;
            var t = repo.GetAll().FirstOrDefault(x => x.GoodId == id);

            goodModel = new GoodViewModel(t, repoCategory, repoManufacturer);
            return(View(goodModel));
        }
Ejemplo n.º 9
0
        public ActionResult Index(GoodViewModel goodViewModel)
        {
            var predicate = PredicateBuilder.New <Good>();
            var pred      = PredicateBuilder.New <Good>();

            predicate.And(x => x.Price >= goodViewModel.From);
            predicate.And(x => x.Price <= goodViewModel.To);

            foreach (var filter in goodViewModel.Filters)
            {
                var catPred = PredicateBuilder.New <Good>();
                catPred.And(x => filter.IsCategoryChecked);
                catPred.And(x => x.CategoryId == filter.CategoryId);
                pred.Extend(catPred);
                var manPred = PredicateBuilder.New <Good>();
                manPred.And(x => filter.IsManufacturerChecked);
                manPred.And(x => x.ManufacturerId == filter.ManufacturerId);
                pred.Extend(manPred);
            }

            predicate.Extend(pred);

            var gvm = new GoodViewModel
            {
                Goods = repository.FindBy(predicate)
            };

            Fill(gvm);

            switch (goodViewModel.Sorting)
            {
            case "Name_Desc":
                gvm.Goods = gvm.Goods.OrderByDescending(x => x.GoodName);
                break;

            case "Price":
                gvm.Goods = gvm.Goods.OrderBy(x => x.Price);
                break;

            case "Price_Desc":
                gvm.Goods = gvm.Goods.OrderByDescending(x => x.Price);
                break;

            case "Count":
                gvm.Goods = gvm.Goods.OrderBy(x => x.GoodCount);
                break;

            case "Count_Desc":
                gvm.Goods = gvm.Goods.OrderByDescending(x => x.GoodCount);
                break;

            default:
                gvm.Goods = gvm.Goods.OrderBy(x => x.GoodName);
                break;
            }

            return(View(gvm));
        }
Ejemplo n.º 10
0
        public ActionResult Create()
        {
            var vm = new GoodViewModel();

            vm.Categories = new SelectList(categoryRepository
                                           .GetAll(), "CategoryId", "CategoryName");

            return(View(vm));
        }
Ejemplo n.º 11
0
        public ActionResult Create()
        {
            GoodViewModel goodViewModel = new GoodViewModel();

            goodViewModel.ManufacturerVM = _manufacturerRepository.Get().ToList();
            goodViewModel.TypeVM         = _typeRepository.Get().ToList();

            return(View(goodViewModel));
        }
Ejemplo n.º 12
0
        public ActionResult Add()
        {
            var viewModel = new GoodViewModel
            {
                Manufacturers = new SelectList(_manufacturerRepository.GetAll(), "ManufacturerId", "ManufacturerName"),
                Categories    = new SelectList(_categoryRepository.GetAll(), "CategoryId", "CategoryName")
            };

            return(View(viewModel));
        }
Ejemplo n.º 13
0
        public ActionResult Index()
        {
            GoodViewModel goodViewModel = new GoodViewModel
            {
                Goods = repository.GetAll(),
            };

            Fill(goodViewModel);
            return(View(goodViewModel));
        }
Ejemplo n.º 14
0
        // GET: Shop
        public ActionResult Index()
        {
            GoodViewModel goodViewModel = new GoodViewModel(categoryRepository, manufacturerRepository)
            {
                Goods = goodRepository.GetAll()
            };

            Fill(goodViewModel);
            return(View(goodViewModel));
        }
Ejemplo n.º 15
0
 public ActionResult AddNew()
 {
     goodModel = new GoodViewModel();
     repo.Add(new Good()
     {
         GoodName = "Inputname", Price = 0, GoodCount = 0
     });
     goodIdForSavingImage = repo.LastId;
     return(View(goodModel));
 }
Ejemplo n.º 16
0
        public ActionResult Index(GoodViewModel goodViewModel)
        {
            var predicate = PredicateBuilder.New <Good>();

            predicate.And(x => x.Price >= goodViewModel.PriceFrom);
            predicate.And(x => x.Price <= goodViewModel.PriceTo);

            foreach (var filter in goodViewModel.Filters)
            {
                var catPred = PredicateBuilder.New <Good>();
                catPred.And(x => filter.IsCategoryChecked);
                catPred.And(x => x.CategoryId == filter.CategoryId);
                predicate.Extend(catPred);
                var manPred = PredicateBuilder.New <Good>();
                manPred.And(x => filter.IsManufacturerChecked);
                manPred.And(x => x.ManufacturerId == filter.ManufacturerId);
                predicate.Extend(manPred);
            }

            var gvm = new GoodViewModel(categoryRepository, manufacturerRepository)
            {
                Goods = goodRepository.FindBy(predicate)
            };

            Fill(gvm);

            switch (goodViewModel.SortParameter)
            {
            case "From Z-A":
                gvm.Goods = gvm.Goods.OrderByDescending(x => x.GoodName);
                break;

            case "From cheap to expensive":
                gvm.Goods = gvm.Goods.OrderBy(x => x.Price);
                break;

            case "From expensive to cheap":
                gvm.Goods = gvm.Goods.OrderByDescending(x => x.Price);
                break;

            case "From lower to highest":
                gvm.Goods = gvm.Goods.OrderBy(x => x.GoodCount);
                break;

            case "From highest to lowest":
                gvm.Goods = gvm.Goods.OrderByDescending(x => x.GoodCount);
                break;

            default:
                gvm.Goods = gvm.Goods.OrderBy(x => x.GoodName);
                break;
            }

            return(View(gvm));
        }
Ejemplo n.º 17
0
        public IHttpActionResult GetGood(int id)
        {
            var good = db.Goods.Find(id);

            if (good == null)
            {
                return(NotFound());
            }

            return(Ok(GoodViewModel.ToGoodViewModel(good)));
        }
Ejemplo n.º 18
0
        public ActionResult Create(GoodViewModel vm)
        {
            repo.CreateOrUpdate(new Good
            {
                GoodName  = vm.GoodName,
                Price     = vm.Price,
                GoodCount = vm.GoodCount
            });

            return(View());
        }
Ejemplo n.º 19
0
        public IHttpActionResult CreateGood([FromBody] Good good)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Goods.Add(good);
            db.SaveChanges();

            return(CreatedAtRoute("PostGoodImage", new { id = good.GoodId }, GoodViewModel.ToGoodViewModel(good)));
        }
Ejemplo n.º 20
0
 public ActionResult Edit(GoodViewModel good)
 {
     if (ModelState.IsValid)
     {
         var newGood = new Good(good);
         repo.Update(newGood);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Edit"));
     }
 }
Ejemplo n.º 21
0
        public GoodViewModel GetGood(int id)
        {
            GoodViewModel result = new GoodViewModel();

            var good = context.GetGood(id);

            result.Id      = good.Id;
            result.Name    = good.Name;
            result.Amount  = good.Amount;
            result.BarCode = good.BarCode;

            return(result);
        }
Ejemplo n.º 22
0
        public ActionResult Create(GoodViewModel gvm)
        {
            _goodRepo.AddOrUpdate(new DAL.Models.Good
            {
                GoodId         = gvm.GoodId,
                CategoryId     = gvm.CategoryId,
                GoodCount      = gvm.GoodCount,
                GoodName       = gvm.GoodName,
                ManufacturerId = gvm.ManufacturerId,
                Price          = gvm.Price
            });

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Update(int id)
        {
            var g = await unit.Goods.GetByIdAsync(id);

            if (g != null)
            {
                GoodViewModel vm = new GoodViewModel {
                    good = g, CategoryId = g.CategoryId
                };
                ViewData["CategoryId"] = new SelectList(await unit.Categories.GetAllAsync(), "Id", "CategoryName");
                return(View(vm));
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 24
0
        public PartialViewResult GetTableGoods(int id = 1)
        {
            var model = new GoodViewModel
            {
                GoodsList    = BusinessGoods.Skip((id - 1) * pagesize).Take(pagesize),
                PageLinkInfo = new PageLinkModel
                {
                    CurrentPage  = id,
                    TotalItems   = BusinessGoods.Count(),
                    CountPerPage = pagesize
                }
            };

            return(PartialView(model));
        }
Ejemplo n.º 25
0
        public ActionResult Index(int id = 1)
        {
            var model = new GoodViewModel
            {
                GoodsList    = BusinessGoods.Skip((id - 1) * pagesize).Take(pagesize),
                PageLinkInfo = new PageLinkModel
                {
                    CurrentPage  = id,
                    TotalItems   = BusinessGoods.Count(),
                    CountPerPage = pagesize
                }
            };

            return(View(model));
        }
Ejemplo n.º 26
0
        public void TestGoodService_GetGood_ShouldReturnGood()
        {
            // Arrange
            var goodResult = new GoodViewModel {
                Id = 1, Name = "Bread Borodinskiy", Amount = 80, BarCode = 54329876
            };
            GoodService ps = new GoodService(new FakeContext());
            // Act
            var result = ps.GetGood(1);

            // Assert
            Assert.AreEqual(true, (goodResult.Id == result.Id) &&
                            (goodResult.Amount == result.Amount) &&
                            (goodResult.Name == result.Name) &&
                            (goodResult.BarCode == result.BarCode));
        }
Ejemplo n.º 27
0
 private void Fill(GoodViewModel goodViewModel)
 {
     goodViewModel.Filters = new List <Filtration>();
     foreach (var category in categoryRepository.GetAll())
     {
         goodViewModel.Filters.Add(new Filtration {
             CategoryId = category.CategoryId, CategoryName = category.CategoryName
         });
     }
     foreach (var manufacturer in manufacturerRepository.GetAll())
     {
         goodViewModel.Filters.Add(new Filtration {
             ManufacturerId = manufacturer.ManufacturerId, ManufacturerName = manufacturer.ManufacturerName
         });
     }
 }
Ejemplo n.º 28
0
        public void AddOrUpdate([NotNull] GoodViewModel value)
        {
            var db_val = _db_Context.Goods.FirstOrDefault(x => x.Id == value.Id);

            if (db_val == null)
            {
                db_val = new Good();
                _db_Context.Add(db_val);
            }
            //set props
            db_val.Name = value.Name;


            _db_Context.ChangeTracker.DetectChanges();
            _db_Context.SaveChanges();
        }
        public IActionResult Goods(GoodStatus goodsStatus = GoodStatus.Active)
        {
            var currentUser = _repositoryUser.GetCurrentUser(User.Identity.Name);

            if (currentUser != null)
            {
                var Company = _repositoryCompany.GetUserCompany(currentUser);
                var Goods   = _repositoryGood.ShopGoodsFullInformation(Company.Id).ToList();

                List <GoodViewModel> GoodsVM = new List <GoodViewModel>();
                foreach (var good in Goods)
                {
                    GoodViewModel gvm = new GoodViewModel
                    {
                        Amount      = good.Amount,
                        Category    = good.Category,
                        CategoryId  = good.CategoryId,
                        Companies   = good.Companies,
                        Description = good.Description,
                        Id          = good.Id,
                        Images      = good.Images,
                        Title       = good.Title
                    };
                    if (good.Images.Count != 0)
                    {
                        gvm.MainImageInBase64 = FromByteToBase64Converter.GetImageBase64Src(good.Images.ToList()[0]);
                    }
                    GoodsVM.Add(gvm);
                }
                ViewBag.GoodsVM = GoodsVM;
            }
            else
            {
                Redirect("/");
            }

            ViewBag.ActiveSubMenu = "Товары/Услуги";
            if (goodsStatus == GoodStatus.Active)
            {
                ViewBag.ActiveGoodsStatusMenu = 1;
            }
            if (goodsStatus == GoodStatus.InActive)
            {
                ViewBag.ActiveGoodsStatusMenu = 0;
            }
            return(View());
        }
Ejemplo n.º 30
0
        public PartialViewResult GoodEdit(int id = 1)
        {
            var manufacturers = service2.GetAll();
            var categories    = service3.GetAll();

            if (id < 0)
            {
                GoodDTO createDTO = new GoodDTO();
                service.CreateOrUpdate(createDTO);
                goodViewModel = new GoodViewModel
                {
                    Good     = createDTO,
                    Category = categories.ToList().Select(category => new SelectListItem
                    {
                        Value = category.CategoryId.ToString(),
                        Text  = category.CategoryName
                    }),
                    Manufacturer = manufacturers.ToList().Select(manufacturer => new SelectListItem
                    {
                        Value = manufacturer.ManufacturerId.ToString(),
                        Text  = manufacturer.ManufacturerName
                    }

                                                                 ),
                };
                return(PartialView(goodViewModel));
            }
            GoodDTO good = service.Get(id);

            goodViewModel = new GoodViewModel
            {
                Good     = good,
                Category = categories.ToList().Select(category => new SelectListItem
                {
                    Value = category.CategoryId.ToString(),
                    Text  = category.CategoryName
                }),
                Manufacturer = manufacturers.ToList().Select(manufacturer => new SelectListItem
                {
                    Value = manufacturer.ManufacturerId.ToString(),
                    Text  = manufacturer.ManufacturerName
                }

                                                             ),
            };
            return(PartialView(goodViewModel));
        }