public async Task <IActionResult> Create(ProductCountry ProductCountry) { //if all poramiters which are required is ok(no nulls) if (ModelState.IsValid) { _db.Add(ProductCountry); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ProductCountry)); }
public async Task <IActionResult> Edit(int id, ProductCountry ProductCountry) { if (id != ProductCountry.Id) { return(NotFound()); } //if all poramiters which are required is ok(no nulls) if (ModelState.IsValid) { _db.Update(ProductCountry); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ProductCountry)); }
public IActionResult Add([FromBody] ProductCountry ProductCountry) { if (ProductCountry.Id == 0) { if (repo.IsNameExist(ProductCountry.Name)) { var payload2 = new { name = ProductCountry.Name, status = "Already Exist" }; return(Ok(payload2)); } var newCountry = repo.Add(ProductCountry); repo.Commit(); var payload = new { name = newCountry.Name, status = "Added" }; return(Ok(payload)); // Status 200 : OK , } else { var updatedCountry = repo.Update(ProductCountry); repo.Commit(); var payload = new { name = updatedCountry.Name, status = "Updated" }; return(Ok(payload)); } }
private async Task <IPagedList <ProductsAllViewModel> > GetProductsByCountryAsync(int?page, ProductCountry type) { int pageNumber = page ?? 1; int pageSize = 6; var wantedProducts = await this.productsService.GetFoodListByCategoryAsync(pageNumber, pageSize, type); return(wantedProducts); }
public Task <IPagedList <ProductsAllViewModel> > GetFoodListByCategoryAsync(int pageNumber, int pageSize, ProductCountry type) { return(this.db.Products.Where(x => x.ProductCountry == type) .ProjectTo <ProductsAllViewModel>(this.mapper.ConfigurationProvider) .ToPagedListAsync(pageNumber, pageSize)); }