public async Task <IActionResult> Get(int id) { var warehouse = await _warehouseRepository.GetByIdAsync(id); var model = new WarehouseIndexViewModel { Id = warehouse.Id, Name = warehouse.Name, Address = warehouse.Address, Vendor = warehouse.Vendor }; return(View(model)); }
public async Task <IActionResult> Post(WarehouseIndexViewModel model) { var warehouse = new Warehouse { Id = model.Id, Name = model.Name, Address = model.Address, Vendor = model.Vendor }; await _warehouseRepository.AddAsync(warehouse); TempData["SM"] = "Вы успешно создали."; return(RedirectToAction("Index", "Warehouse")); }
public async Task <IActionResult> Put(int id, WarehouseIndexViewModel model) { var warehouse = await _warehouseRepository.GetByIdAsync(id); if (warehouse == null) { return(NotFound()); } model.Name = warehouse.Name; model.Address = warehouse.Address; model.Vendor = warehouse.Vendor; return(View(model)); }
// GET: Warehouses public ActionResult Index(string SearchString, String city, double from = 0.0, double to = 0.0, int page = 1, int numberofDoor = 1) { var warehouses = db.Warehouses.OfType <Warehouse>() .Where(w => w.Ad.User.Confirmed) .Include(l => l.Ad); ViewBag.Views = db.Views; ViewBag.Wishlists = db.Wishlists; if (!String.IsNullOrEmpty(SearchString)) { warehouses = warehouses.Where(a => a.Ad.City.Name.ToUpper().Contains(SearchString.ToUpper()) || a.Ad.AdDescribtion.ToUpper().Contains(SearchString.ToUpper()) || a.Ad.AdTitle.ToUpper().Contains(SearchString.ToUpper())); } if (!String.IsNullOrEmpty(city)) { warehouses = warehouses.Where(a => a.Ad.City.Name.ToUpper().Equals(city)); } if (to >= from && to > 1 && from >= 0.0) { warehouses = warehouses.Where(a => a.Ad.AdPrice >= from && a.Ad.AdPrice <= to); } var cities = warehouses.Select(c => c.Ad.City.Name).Distinct(); ViewBag.city = new SelectList(cities); //pagination steps int pageSize = 6; var pager = new Pager(warehouses.Count(), page, pageSize); WarehouseIndexViewModel vModel = new WarehouseIndexViewModel() { Warehouses = warehouses.OrderBy(a => a.Ad.AdPrice).Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize), Pager = pager, SearchString = SearchString, City = city, NumberofDoor = numberofDoor, From = from, To = to }; return(View(vModel)); }
public async Task <IActionResult> Put(WarehouseIndexViewModel model) { if (!ModelState.IsValid) { return(NotFound()); } var warehouse = new Warehouse { Id = model.Id, Name = model.Name, Address = model.Address, Vendor = model.Vendor }; await _warehouseRepository.UpdateAsync(warehouse); TempData["SM"] = "Вы успешно изменили."; return(RedirectToAction("Index")); }