public ActionResult GetUpdateItem(int itemId) { Item item = ApplicationDbContext.Items.FirstOrDefault(i => i.ItemId == itemId); Category categoryName = ApplicationDbContext.Categories.FirstOrDefault(i => i.CategoryId == item.CategoryId); List <Category> categoryList = ApplicationDbContext.Categories.ToList(); UpdateItemViewModel viewModel = null; if (item != null && categoryName != null) { viewModel = new UpdateItemViewModel { ItemId = item.ItemId, Name = item.Name, Price = item.Price, ImageReference = item.ImageReference, DateAdded = item.DateAdded, Description = item.Description, CategoryName = categoryName.CategoryName, Categories = categoryList }; } return(View("UpdateItem", viewModel)); }
public async Task <IActionResult> UpdateAsync([FromBody] UpdateItemViewModel updateItemViewModel) { var updateItemDto = _mapper.Map <UpdateItemDto>(updateItemViewModel); var updatedItemDto = await _itemService.UpdateAsync(updateItemDto); var updatedItemViewModel = _mapper.Map <ItemViewModel>(updatedItemDto); return(Ok(updatedItemViewModel)); }
public IActionResult UpdateItem(int id) { var selectedItem = _itemService.GetAll().FirstOrDefault(x => x.Id == id); //_dropdownHelper.CategoryDropdown(); var selectedItemWithType = _itemService.GetItemType().FirstOrDefault(x => x.Id == id); var item = new UpdateItemViewModel() { Description = selectedItemWithType.Description, Cost = selectedItemWithType.Cost, SerialNumber = selectedItemWithType.SerialNumber, Name = selectedItemWithType.ItemType.Name, CategoryId = selectedItemWithType.ItemType.CategoryId, Id = id }; return(View(item)); }
public IActionResult Put(UpdateItemViewModel itemViewModel) { var item = new Item { Id = int.Parse(itemViewModel.Id), Title = itemViewModel.Title, Description = itemViewModel.Description, IsDone = itemViewModel.IsDone }; try { itemRepository.Update(item); return(Ok(new { Message = "Item successfully updated." })); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public IActionResult UpdateItem(UpdateItemViewModel model) { if (ModelState.IsValid) { _dropdownHelper.CategoryDropdown(); Item item = new Item() { SerialNumber = model.SerialNumber, Description = model.Description, Cost = model.Cost, Id = model.Id, ItemType = new ItemType { Name = model.Name, CategoryId = model.CategoryId } }; TempData["ItemMessage"] = @$ "Eşya {item.ItemType.Name} güncellendi"; _itemService.Update(item); } return(RedirectToAction(nameof(ItemList))); }
public ActionResult UpdateItem(UpdateItemViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } Item itemToUpdate = ApplicationDbContext.Items.First(i => i.ItemId == viewModel.ItemId); itemToUpdate.Name = viewModel.Name; itemToUpdate.Description = viewModel.Description; itemToUpdate.Price = viewModel.Price; itemToUpdate.ImageReference = viewModel.ImageReference; List <int> itemSubcategory = ApplicationDbContext.SubCategoryItems.Where(i => i.ItemId == viewModel.ItemId).Select(i => i.SubcategoryId).ToList(); //Check for new subcategory to add to junction table. If sub count is 0 then all check will be added. if itemSubcategory does not contain the subcategoryId (sub) then it will be added //Add subcategories if (viewModel.Subcategories != null) { foreach (int sub in viewModel.Subcategories) { if (itemSubcategory.Count < 1 || !itemSubcategory.Contains(sub)) { SubCategoryItems newSubcatItem = new SubCategoryItems { SubcategoryId = sub, ItemId = viewModel.ItemId }; ApplicationDbContext.SubCategoryItems.Add(newSubcatItem); } } } //Check to see if subcategory was uncheck and will be removed. //remove subcategories if (viewModel.Subcategories == null) { var removeAll = ApplicationDbContext.SubCategoryItems .Where(i => i.ItemId == viewModel.ItemId); ApplicationDbContext.SubCategoryItems .RemoveRange(removeAll); } else { foreach (var itemSub in itemSubcategory) { if (!viewModel.Subcategories.Contains(itemSub)) { //remove unchecked subcategory from item SubCategoryItems removeSingle = ApplicationDbContext.SubCategoryItems .Where(i => i.ItemId == viewModel.ItemId) .First(i => i.SubcategoryId == itemSub); ApplicationDbContext.SubCategoryItems .Remove(removeSingle); ApplicationDbContext.SaveChanges(); } } } ApplicationDbContext.SaveChanges(); List <Category> categoryList = ApplicationDbContext.Categories.ToList(); viewModel.Categories = categoryList; return(View("UpdateItem", viewModel)); }
public UpdateItemPage() { InitializeComponent(); BindingContext = _viewModel = new UpdateItemViewModel(); LoadCategories(); }
public HttpResponseMessage Put(int id, UpdateItemViewModel item) { ItemServices.AtualizaItem(id, item); return(Request.CreateResponse(HttpStatusCode.OK, new DescriptionMessage(HttpStatusCode.OK, "Item Updated", $"Item #{id} Updated"))); }