public async Task <IActionResult> AddFreight([FromBody] AppFreight model) { if (ModelState.IsValid) { try { var addedFreight = await freightRepo.AddFreight(model); if (addedFreight != null) { return(Ok(addedFreight)); } else { return(NotFound()); } } catch (Exception excp) { return(BadRequest(excp)); } } return(BadRequest()); }
public async Task <AppFreight> UpdateFreight(AppFreight freight) { if (db != null) { //Delete that post db.AppFreight.Update(freight); //Commit the transaction await db.SaveChangesAsync(); } return(freight); }
public async Task <AppFreight> AddFreight(AppFreight freight) { if (db != null) { freight.AppFreightId = Guid.NewGuid(); freight.CreatedDate = DateTime.Now; await db.AppFreight.AddAsync(freight); await db.SaveChangesAsync(); return(freight); } return(freight); }
public async Task <IActionResult> UpdateFreight([FromBody] AppFreight freight) { if (ModelState.IsValid) { try { await freightRepo.UpdateFreight(freight); return(Ok()); } catch (Exception excp) { if (excp.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest(excp)); } } return(BadRequest()); }