コード例 #1
0
ファイル: ItemPriceService.cs プロジェクト: iraqnroll/PSI
        public async Task <ServiceResponse <List <GetItemPriceDto> > > AddItemPrice(AddItemPriceDto newItemPrice)
        {
            ServiceResponse <List <GetItemPriceDto> > serviceResponse = new ServiceResponse <List <GetItemPriceDto> >();

            var item = await _context.Items.FirstOrDefaultAsync(x => x.Id == newItemPrice.ItemId);

            var receipt = await _context.Receipts.FirstOrDefaultAsync(x => x.Id == newItemPrice.ReceiptId);

            if (item == null)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "Item not found";
                return(serviceResponse);
            }

            if (receipt == null)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "Receipt not found";
                return(serviceResponse);
            }

            var itemprice = _mapper.Map <ItemPrice>(newItemPrice);

            await _context.ItemPrices.AddAsync(itemprice);

            await _context.SaveChangesAsync();

            return(await GetAllItemPrices());
        }
コード例 #2
0
ファイル: ItemPriceController.cs プロジェクト: iraqnroll/PSI
        public async Task <IActionResult> AddItemPrice(AddItemPriceDto newItemPrice)
        {
            var serviceResponse = await _itemPriceService.AddItemPrice(newItemPrice);

            if (serviceResponse.Success == false)
            {
                return(NotFound(serviceResponse));
            }
            else
            {
                return(Ok(serviceResponse));
            }
        }