protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public async Task <IHttpActionResult> AddUpdateUserBio(UserBio userBio) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (id != userBio.Id) //{ // return BadRequest(); //} bool isEdit = false; //userBio.Id = this.LoggedInUserId; if (this.LoggedInUserId != userBio.Id) { return(BadRequest()); } if (this.LoggedInAspNetUser.UserBio == null) { //ModelState.AddModelError("UserBioNotFound", "No record found to be updated"); //return BadRequest(ModelState); isEdit = false; db.UserBios.Add(userBio); } if (this.LoggedInAspNetUser.UserBio != null) { isEdit = true; db.Entry(userBio).State = EntityState.Modified; } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { Logger.Error(ex); throw; } catch (DbUpdateException dbex) { Logger.Error(dbex); if (UserBioExists(userBio.Id)) { return(Conflict()); } else { throw; } } if (!isEdit) { return(CreatedAtRoute("DefaultApi", new { id = userBio.Id }, userBio)); } db.Dispose(); HttpResponseMessage Updateresponse = new HttpResponseMessage(HttpStatusCode.OK); Updateresponse.Content = new StringContent("Record Updated Successfully"); return(Ok("Record Updated Successfully")); }