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));
     }
 }
예제 #2
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));
     }
 }