public async Task <IHttpActionResult> PutLoginProfile(int id, LoginProfileVM loginProfileVM) { LoginProfile loginProfile = ConvertToDBModel(loginProfileVM); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != loginProfile.ID) { return(BadRequest()); } db.Entry(loginProfile).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoginProfileExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private LoginProfile ConvertToDBModel(LoginProfileVM l) { return(new LoginProfile { ID = l.ID, Password = l.Password, Username = l.Username, CreatedOn = l.CreatedOn }); }
public async Task <IHttpActionResult> PostLoginProfile(LoginProfileVM loginProfile) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.LoginProfiles.Add(ConvertToDBModel(loginProfile)); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = loginProfile.ID }, loginProfile)); } catch (Exception ex) { throw ex; } }