public HttpResponseMessage Delete(HttpRequestMessage request, int id) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { _productTagService.Delete(id); _productTagService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public async Task <IActionResult> Edit(int Id, Product viewModel, string[] SelectedCategories, string[] SelectedTags, ICollection <IFormFile> files, IFormFile file) { if (Id == null) { return(NotFound()); } if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated) { return(NotFound()); } if (ModelState.IsValid) { try { await _productService.AddFile(viewModel, file); await _productShopCategoryService.Delete(Id); await _productTagService.Delete(Id); await _productMediaService.Add(viewModel, files); await _productShopCategoryService.Add(viewModel, SelectedCategories); await _productTagService.Add(viewModel, SelectedTags); await _productService.Update(viewModel); if (!String.IsNullOrEmpty(Request.Form["continue"])) { return(RedirectToAction("Edit", new { Id = Id })); } if (!String.IsNullOrEmpty(Request.Form["new"])) { return(RedirectToAction(nameof(Create))); } return(RedirectToAction(nameof(Index))); } catch (DBConcurrencyException) { var exists = await Exists(viewModel.Id); if (!exists) { return(NotFound()); } else { throw; } } } var products = await _productService.GetAll(); ViewBag.Products = new SelectList(products.ToList(), "Id", "Title", viewModel.ParentId); ViewBag.Brands = new SelectList(await _brandService.GetAll(), "Id", "Title", viewModel.BrandId); viewModel.SelectedCategories = viewModel.ProductShopCategories.Select(c => c.ShopCategoryId).AsEnumerable(); ViewBag.SelectedCategories = new SelectList(await _shopCategoryService.GetAll(), "Id", "Title", viewModel.SelectedCategories); viewModel.SelectedTags = viewModel.ProductTags.Select(c => c.TagId).AsEnumerable(); ViewBag.SelectedTags = new SelectList(await _tagService.GetAll(), "Id", "Title", viewModel.SelectedTags); return(View(viewModel)); }