Ejemplo n.º 1
0
 public HttpResponseMessage CreatePerson([FromBody] PersonAPIModel person, [FromUri] int approverId)
 {
     try
     {
         if (ModelState.IsValid)
         {
             UserAPIModel  user  = mapper.Map <UserAPIModel>(userBDC.GetUserById(approverId));
             HouseAPIModel house = mapper.Map <HouseAPIModel>(houseBDC.GetHouseByCHN(person.CensusHouseNumber));
             if (user.CurrentStatus == APIModels.status.Approved)
             {
                 if (house != null)
                 {
                     person.CreatedBy = approverId;
                     person.HouseId   = house.ID;
                     if (personBDC.CreatePerson(mapper.Map <PersonDTO>(person)))
                     {
                         System.Diagnostics.Debug.WriteLine(person);
                         return(Request.CreateResponse(HttpStatusCode.OK, true));
                     }
                     else
                     {
                         return(Request.CreateResponse(HttpStatusCode.OK, false));
                     }
                 }
                 else
                 {
                     return(Request.CreateResponse(HttpStatusCode.OK, false));
                 }
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, Resources.Forbidden));
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
 public HttpResponseMessage CreateHouseListing([FromBody] HouseAPIModel house, [FromUri] int approverId)
 {
     try
     {
         if (ModelState.IsValid)
         {
             UserAPIModel user          = mapper.Map <UserAPIModel>(userBDC.GetUserById(approverId));
             Boolean      isHouseExists = (houseBDC.CheckCHN(house.CensusHouseNumber));
             if (user.CurrentStatus == APIModels.status.Approved)
             {
                 if (isHouseExists == false)
                 {
                     house.CreatedBy = user.ID;
                     if (houseBDC.CreateHouseListing(mapper.Map <HouseDTO>(house)))
                     {
                         System.Diagnostics.Debug.WriteLine(house);
                         string chn = house.CensusHouseNumber.ToString();
                         return(Request.CreateResponse(HttpStatusCode.OK, chn));
                     }
                     else
                     {
                         return(Request.CreateResponse(HttpStatusCode.OK, false));
                     }
                 }
                 else
                 {
                     return(Request.CreateResponse(HttpStatusCode.OK, false));
                 }
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, Resources.Forbidden));
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, false));
         }
     }
     catch (Exception)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, false));
     }
 }
Ejemplo n.º 3
0
 public HttpResponseMessage ApproveUser([FromBody] ApproverAPIID approverId, [FromUri] int userId)
 {
     try
     {
         UserAPIModel user = mapper.Map <UserAPIModel>(userBDC.GetUserById(userId));
         if (user == null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, false));
         }
         else
         {
             if (user.CurrentStatus == APIModels.status.Pending)
             {
                 user.CurrentStatus = APIModels.status.Approved;
                 user.ApprovedBy    = approverId.ApproverId;
                 UserDTO userToUpdate = mapper.Map <UserDTO>(user);
                 if (userBDC.UpdateUser(userToUpdate))
                 {
                     return(Request.CreateResponse(HttpStatusCode.OK, true));
                 }
                 else
                 {
                     return(Request.CreateResponse(HttpStatusCode.OK, false));
                 }
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, false));
             }
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.Message);
         return(Request.CreateResponse(HttpStatusCode.Forbidden, e));
     }
 }
Ejemplo n.º 4
0
        public OperationResult <IUserDTO> GetUserById(string id)
        {
            IUserBDC UserBDC = (IUserBDC)BDCFactory.Instance.Create(BDCType.UserBDC);

            return(UserBDC.GetUserById(id));
        }