Пример #1
0
 public Item DTOToItem(NewItemDTO givenItemDTO)
 {
     return(new Item(
                givenItemDTO.Name,
                givenItemDTO.Price,
                givenItemDTO.Amount,
                givenItemDTO.Description
                ));
 }
Пример #2
0
 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)); }
 }
Пример #3
0
 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)); }
 }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
        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)));
        }
Пример #7
0
        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();
        }