コード例 #1
0
        public async Task <ItemsInStockModel> AddAsync(ItemsInStockModel model)
        {
            await StockEntities.AddAsync(model);

            await Context.SaveChangesAsync();

            return(model);
        }
コード例 #2
0
 public async Task <int> UpdateAsync(ItemsInStockModel model)
 {
     if (model.ItemsInStock > -1)
     {
         Context.Entry(model).State = EntityState.Modified;
         return(await Context.SaveChangesAsync());
     }
     throw new ArgumentException("Item Out Of Stock");
 }
コード例 #3
0
        public async Task <IActionResult> UpdateItemsInStock([FromBody] ItemsInStockModel model)
        {
            try
            {
                await ItemsInStockService.UpdateAsync(model);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Post(VehiclesForSaleViewModel viewModel)
        {
            try
            {
                var file = Request.Form.Files[0];

                viewModel.VehicleMake    = Request.Form["vehicleMake"].ToString();
                viewModel.VehicleModel   = Request.Form["vehicleModel"].ToString();
                viewModel.Price          = Convert.ToInt32(Request.Form["price"]);
                viewModel.ItemsInStockId = Convert.ToInt32(Request.Form["itemsInStockId"]);
                viewModel.ItemsInStock   = Convert.ToInt32(Request.Form["itemsInStock"]);
                VehiclesForSale model = new VehiclesForSale
                {
                    Id             = viewModel.Id,
                    VehicleMake    = viewModel.VehicleMake,
                    VehicleModel   = viewModel.VehicleModel,
                    VehiclePicture = viewModel.VehiclePicture,
                    Price          = viewModel.Price
                };


                if (file.Length > 0)
                {
                    ItemsInStockModel stockModel = new ItemsInStockModel();
                    stockModel.ItemsInStock      = viewModel.ItemsInStock;
                    stockModel.VehiclesForSaleId = viewModel.ItemsInStockId;
                    stockModel.Id = viewModel.Id;
                    using (var memoryStream = new MemoryStream())
                    {
                        await file.CopyToAsync(memoryStream);

                        model.VehiclePicture = memoryStream.ToArray();
                    }
                    try
                    {
                        await VehiclesForSaleService.CreateAsync(model);
                    }
                    catch (Exception ex)
                    {
                        return(BadRequest(ex.Message));
                    }

                    await ItemsInStockService.AddAsync(stockModel);
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #5
0
 public async Task <int> UpdateAsync(ItemsInStockModel model)
 {
     return(await ItemsInStockRepository.UpdateAsync(model));
 }
コード例 #6
0
 public async Task <ItemsInStockModel> AddAsync(ItemsInStockModel model)
 {
     return(await ItemsInStockRepository.AddAsync(model));
 }