public HttpResponseMessage SaveUser([FromBody] User user) { try { if (ModelState.IsValid) { //if (Mail.networkIsAvailable()) //{ string errMsg = string.Empty; user.CreatedOn = System.DateTime.Now; user.FirstTime = true; string password = System.Web.Security.Membership.GeneratePassword(8, 0); user.HashedPassword = PasswordHash.MD5Hash(password); bool result = UserPL.Save(user, out errMsg); if (string.IsNullOrEmpty(errMsg)) { if (result) { user.HashedPassword = password; Mail.SendNewUserMail(user); return(Request.CreateResponse(HttpStatusCode.OK, "User added successfully.")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed")); } } else { var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg); return(response); } //} //else //{ //return Request.CreateResponse(HttpStatusCode.BadRequest, "Kindly ensure that internet connection is available before creating a user"); //} } else { string errors = ModelStateValidation.GetErrorListFromModelState(ModelState); return(Request.CreateResponse(HttpStatusCode.BadRequest, errors)); } } catch (Exception ex) { ErrorHandler.WriteError(ex); var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return(response); } }
public HttpResponseMessage SaveUser([FromBody] User user) { try { string errMsg = string.Empty; user.CreatedOn = System.DateTime.Now; user.FirstTime = true; string password = System.Web.Security.Membership.GeneratePassword(8, 0); user.HashedPassword = password; bool result = UserPL.Save(user, out errMsg); if (string.IsNullOrEmpty(errMsg)) { if (result) { user.HashedPassword = password; Mail.SendNewUserMail(user); return(Request.CreateResponse(HttpStatusCode.OK, "User added successfully.")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed")); } } else { var response = Request.CreateResponse(HttpStatusCode.BadRequest, errMsg); return(response); } } catch (Exception ex) { ErrorHandler.WriteError(ex); var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return(response); } }