public Item DTOToItem(NewItemDTO givenItemDTO) { return(new Item( givenItemDTO.Name, givenItemDTO.Price, givenItemDTO.Amount, givenItemDTO.Description )); }
public ActionResult UpdateItem([FromRoute] Guid ItemGuidID, [FromBody] NewItemDTO ItemWithUpdateValues) { try { _itemService.UpdateItem(ItemGuidID, _itemMapper.DTOToItem(ItemWithUpdateValues)); return(Ok()); } catch (ItemException ItemEx) { return(BadRequest(ItemEx.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult AddNewItem([FromBody] NewItemDTO givenItem) { try { _itemService.AddNewItem(_itemMapper.DTOToItem(givenItem)); return(Ok()); } catch (ItemException ItemEx) { return(BadRequest(ItemEx.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <Item> CreateAsync(NewItemDTO dto, User appUser) { var Item = new Item { IsComplete = false, Name = dto.Name, Responsible = appUser }; return(await ItemRepository.Create(Item)); }
public async Task <IActionResult> Create(NewItemViewModel model) { if (ModelState.IsValid) { string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; string username = User.FindFirst(ClaimTypes.Name).Value; NewItemDTO dto = _mappper.Map <NewItemViewModel, NewItemDTO>(model); dto.UserId = userId; dto.Username = username; await _itemService.CreateAsync(dto); return(RedirectToAction("Index", "Home", new { area = "customer" })); } ModelState.AddModelError(string.Empty, "Niepoprawne dane produktu."); return(View(model)); }
public async Task <ActionResult <ItemDTO> > PostTodoItem(NewItemDTO itemDTO) { User appUser = null; if (itemDTO.UserId != null) { appUser = await _userManager.FindByIdAsync(itemDTO.UserId); if (appUser is null) { return(BadRequest("Invalid userId")); } } var Item = await _itemService.CreateAsync(itemDTO, appUser); return(CreatedAtAction("GetTodoItem", new { id = Item.Id }, ItemToDTO(Item))); }
public async Task CreateAsync(NewItemDTO dto) { Item item = _mapper.Map <NewItemDTO, Item>(dto); _photoService.AddPhoto(dto.File); item.Status = Status.Waiting; item.Payment = await _unitOfWork.PaymentRepo.GetById(dto.PaymentId); item.Subcategory = _unitOfWork.CategoryRepo.GetSubcategory(dto.SubcatId); item.UserId = dto.UserId; item.ImgSrc = _photoService.GetLocalFilePath(); item.Username = dto.Username; item.AuctionStart = null; item.AuctionEnd = null; item.Order = null; item.AddDescriptions(_mapper.Map <List <DescriptionDTO>, List <ItemDescription> >(dto.Descriptions)); await _unitOfWork.ItemRepo.Add(item); _unitOfWork.Save(); }