public async Task <IActionResult> AddBrand([FromBody] AppBrand model) { if (ModelState.IsValid) { try { logger.LogInformation("Adding Brand in Repository"); var addedBrand = await BrandRepo.AddBrand(model); if (addedBrand != null) { return(Ok(addedBrand)); } else { return(NotFound()); } } catch (Exception excp) { logger.LogError("Error Adding Brand in Repository " + excp.Message); return(BadRequest(excp)); } } return(BadRequest()); }
public async Task <AppBrand> UpdateBrand(AppBrand brand) { if (db != null) { //Delete that post db.AppBrand.Update(brand); //Commit the transaction await db.SaveChangesAsync(); } return(brand); }
public async Task <AppBrand> AddBrand(AppBrand brand) { if (db != null) { brand.AppBrandId = Guid.NewGuid(); brand.CreatedDate = DateTime.Now; await db.AppBrand.AddAsync(brand); await db.SaveChangesAsync(); return(brand); } return(brand); }
public async Task <IActionResult> UpdateBrand([FromBody] AppBrand Brand) { if (ModelState.IsValid) { try { await BrandRepo.UpdateBrand(Brand); return(Ok()); } catch (Exception excp) { if (excp.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest(excp)); } } return(BadRequest()); }