public BaseResponse UpdateKid(long id, KidRequest kid) { BaseResponse resp = new BaseResponse(); try { if (ValidateRequest.UpdateKid(id, kid)) { var kidCrud = new KidCRUD(); if (new UserCRUD().IsUserExists(id) || kidCrud.IsUserKidExists(kid.Kid.Id)) { if (kidCrud.IsUserKidExists(id, kid.Kid.Id)) { kid.Kid.UserId = id; kidCrud.UpdateKid(kid.Kid); if (kid.Kid.Id > 0) { resp.OK(); } else { resp.Conflict(); } } else resp.Unauthorized(); } else { resp.Conflict(); } } else { resp.BadRequest(); } } catch (Exception es) { string req = JsonConvert.SerializeObject(kid); logger.Error(string.Format("UpdateKid, UserID={0}, Req={1}", id, req)); logger.Error("UpdateKid " + es.StackTrace); resp.InternalServerError(); } return resp; }
public BaseResponse AddKid(long id, [FromBody] KidRequest kid) { BaseResponse resp = new BaseResponse(); try { if (ValidateRequest.AddKid(id, kid)) { if (new UserCRUD().IsUserExists(id)) { var kidCrud = new KidCRUD(); kid.Kid.UserId = id; kidCrud.AddKid(kid.Kid); if (kid.Kid.Id > 0) { resp.OK(); } else { resp.Conflict(); } } else { resp.Conflict(); resp.HttpStatusMessage = Constants.InValidUser; } } else { resp.BadRequest(); } } catch (Exception es) { string req = JsonConvert.SerializeObject(kid); logger.Error(string.Format("AddKid, UserID={0}, Req={1}", id, req)); logger.Error("AddKid " + es.StackTrace); resp.InternalServerError(); } return resp; }
public BaseResponse UpdateHome(long id, HomeRequest home) { BaseResponse resp = new BaseResponse(); try { if (ValidateRequest.UpdateHome(id, home)) { var homeCrud = new HomeCRUD(); if (new UserCRUD().IsUserExists(id) || homeCrud.IsUserHomeExists(home.Home.Id)) { home.Home.UserId = id; homeCrud.UpdateHome(home.Home); if (home.Home.Id > 0) { resp.OK(); } else { resp.Conflict(); } } else { resp.Conflict(); resp.HttpStatusMessage = Constants.InValidUser; } } else { resp.BadRequest(); } } catch (Exception es) { string req = JsonConvert.SerializeObject(home); logger.Error(string.Format("UpdateHome, UserID={0}, Req={1}", id, req)); logger.Error("UpdateHome " + es.StackTrace); resp.InternalServerError(); } return(resp); }
public BaseResponse AddUser(UserRequest user) { BaseResponse resp = new BaseResponse(); try { if (ValidateRequest.AddUser(user)) { var userCrud = new UserCRUD(); if (!userCrud.IsUserExists(user.User.PhoneNumber, user.User.Email) && !userCrud.IsUserExists(user.User.Id)) { user.User.Id = 0; new UserCRUD().AddUser(user.User); if (user.User.Id > 0) { resp.OK(); } else { resp.Conflict(); } } else { resp.Conflict(); } } else { resp.BadRequest(); } } catch (Exception es) { string req = JsonConvert.SerializeObject(user); logger.Error(string.Format("AddUser, Req={0}", req)); logger.Error("AddUser " + es.StackTrace); resp.InternalServerError(); } return(resp); }
public BaseResponse UpdateUser(UserRequest user) { BaseResponse resp = new BaseResponse(); try { if (ValidateRequest.UpdateUser(user)) { if (new UserCRUD().IsUserExists(user.User.Id)) { user.User.IsActive = true; new UserCRUD().UpdateUser(user.User); if (user.User.Id > 0) { resp.OK(); } else { resp.Conflict(); } } else { resp.Conflict(); resp.HttpStatusMessage = Constants.InValidUser; } } else { resp.BadRequest(); } } catch (Exception es) { string req = JsonConvert.SerializeObject(user); logger.Error(string.Format("UpdateUser, Req={0}", req)); logger.Error("UpdateUser " + es.StackTrace); resp.InternalServerError(); } return(resp); }
public BaseResponse InActivateUser(long id) { BaseResponse resp = new BaseResponse(); try { if (ValidateRequest.InActivateUser(id)) { var userCrud = new UserCRUD(); if (userCrud.IsUserExists(id)) { var status = userCrud.InActivateUser(id); if (status > 0) { resp.OK(); } else { resp.Conflict(); } } else { resp.Conflict(); } } else { resp.BadRequest(); } } catch (Exception es) { logger.Error(string.Format("DeleteUser, UserID={0}", id)); logger.Error("DeleteUser " + es.StackTrace); resp.InternalServerError(); } return(resp); }