public async Task <IActionResult> AddSupply([FromBody] AppSupply model) { if (ModelState.IsValid) { try { var addedSupply = await supplyRepo.AddSupplyInfo(model); if (addedSupply != null) { return(Ok(addedSupply)); } else { return(NotFound()); } } catch (Exception excp) { return(BadRequest(excp)); } } return(BadRequest()); }
public async Task <AppSupply> UpdateSupply(AppSupply supply) { if (db != null) { //Delete that post db.AppSupply.Update(supply); //Commit the transaction await db.SaveChangesAsync(); } return(supply); }
public async Task <AppSupply> AddSupplyInfo(AppSupply supply) { if (db != null) { supply.AppSupplyId = Guid.NewGuid(); supply.CreatedDate = DateTime.Now; await db.AppSupply.AddAsync(supply); await db.SaveChangesAsync(); return(supply); } return(supply); }
public async Task <IActionResult> UpdateSupply([FromBody] AppSupply supply) { if (ModelState.IsValid) { try { await supplyRepo.UpdateSupply(supply); return(Ok()); } catch (Exception excp) { if (excp.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest(excp)); } } return(BadRequest()); }