public ShowAllProductsPage(ObservableCollection <Product> products) { InitializeComponent(); BindingContext = viewModel = new ProductsVm(); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); var currentColumn = 0; var currentRow = 0; for (int i = 0; i < products.Count; i++) { Product product = products[i]; if (i % 2 == 0 && i != 0) { grid.RowDefinitions.Add(new RowDefinition()); currentRow++; currentColumn = 0; } grid.Children.Add(CreateFrame(product), currentColumn, currentRow); currentColumn++; } }
public async Task <IHttpActionResult> PostProducts(ProductsVm vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = Task.Factory.StartNew(() => { IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { ProductsRepository }); var bo = (BOProducts)vm.BOProducts(ProductsRepository); uow.Create(bo); string err; if (!uow.Commit(out err)) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(err) }; throw new HttpResponseException(resp); } vm = new ProductsVm(bo); return(true); }); await result; return(CreatedAtRoute("DefaultApi", new { id = vm.İd }, vm)); }
public async Task <IHttpActionResult> PutProducts(string id, ProductsVm vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != vm.İd) { return(BadRequest()); } var result = Task.Factory.StartNew(() => { IUnitOfWork uow = new UnitOfWorkImp(new IRepositoryConnection[] { ProductsRepository }); var bo = (BOProducts)vm.BOProducts(ProductsRepository); uow.Update(bo); string err; if (!uow.Commit(out err)) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(err) }; throw new HttpResponseException(resp); } return(true); }); await result; if (!result.Result) { return(NotFound()); } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult> IndexAsync(Guid categoryId, /*Guid userId,*/ string namePrice = null, int currentPage = 1) { var category = this.dbContext.Categories.FirstOrDefault(cat => cat.Id == categoryId); var userName = HttpContext.User.Identity.Name; var products = this.dbContext.Products.Where(pr => pr.CategoryId == category.Id); if (!string.IsNullOrEmpty(namePrice)) { var isPrice = decimal.TryParse(namePrice, out decimal price); if (isPrice) { var foundProdByPrice = products.Where(p => p.PriceGoods == price); products = foundProdByPrice; } var foundProdsByName = products.Where(p => p.Name.Contains(namePrice)); if (foundProdsByName.Any()) { products = foundProdsByName; } } var count = products.Count(); int pageSize = 6; var model = new ProductsVm() { CategoryId = category.Id, CategoryName = category.Name, }; if (userName != null) { AccountUser accountUser = await userManager.FindByNameAsync(userName); var user = dbContext.Userss.FirstOrDefault(u => u.AccountUser == accountUser); model.UserId = user.Id; } products = products.Skip(pageSize * currentPage - pageSize).Take(pageSize); model.NamePriceFilter = namePrice; model.Pagination = new PaginationViewModel() { TotalCount = count, CurrentPage = currentPage, ControllerName = "Product", ActionName = "Index", ObjectParameter = new Dictionary <string, string> { { "categoryId", category.Id.ToString() } } }; model.Products = products.Select(pr => new ProductVm() { Id = pr.Id, Name = pr.Name, Number = pr.Number, PriceGoods = pr.PriceGoods, Image = pr.Image, Discription = pr.Discription, //CategoryId = pr.CategoryId, //CategoryName = category.Name, }).ToList(); return(View(model)); }
public ProductsPage() { InitializeComponent(); BindingContext = viewModel = new ProductsVm(); }