public async Task <ItemsInStockModel> AddAsync(ItemsInStockModel model) { await StockEntities.AddAsync(model); await Context.SaveChangesAsync(); return(model); }
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"); }
public async Task <IActionResult> UpdateItemsInStock([FromBody] ItemsInStockModel model) { try { await ItemsInStockService.UpdateAsync(model); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
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)); } }
public async Task <int> UpdateAsync(ItemsInStockModel model) { return(await ItemsInStockRepository.UpdateAsync(model)); }
public async Task <ItemsInStockModel> AddAsync(ItemsInStockModel model) { return(await ItemsInStockRepository.AddAsync(model)); }