public void TestAddKid(long userId, string firstName, int age, string lastName) { var con = new UserManagementAPIs.Controllers.KidController(logger); var kidReq = new KidRequest() { Kid = new Kid() { Age = age, FirstName = firstName, LastName = lastName, } }; var result = con.AddKid(userId, kidReq); Assert.Equal(System.Net.HttpStatusCode.OK, result.HttpStatusCode); }
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; }