public Response AddResident(string idNumber)
        {
            Response response = new Response()
            {
                Status = 0, Message = ""
            };

            if (string.IsNullOrEmpty(idNumber))
            {
                return(response);
            }

            IdentityHelper helper = new IdentityHelper(idNumber);

            if (helper.IsValid)
            {
                if (residentRepo.GetByID(idNumber) == null)
                {
                    ResidentEntity residentEntity = new ResidentEntity()
                    {
                        IDNumber = helper.IdentityNumber, DateOfBirth = helper.BirthDate, Gender = helper.Gender, Citizenship = helper.IsSouthAfrican
                    };
                    try
                    {
                        residentRepo.Add(residentEntity);
                        response.Status  = 1;
                        response.Message = helper.IdentityNumber + ": Inserted Successfully";
                        logger.LogInfo(helper.IdentityNumber + ": Inserted Successfully");
                    }
                    catch (Exception ex)
                    {
                        response.Status  = -1;
                        response.Message = "Error occoured while processing the request";
                        logger.LogError("Error occoured in ResidentService.AddResident");
                        logger.LogError(ex.Message);
                    }
                }
                else
                {
                    response.Status  = -2;
                    response.Message = helper.IdentityNumber + " South African ID Number already exist!!";
                    logger.LogWarn(helper.IdentityNumber + " South African ID Number already exist!!");
                }
            }
            else
            {
                response.Status  = -3;
                response.Message = helper.IdentityNumber + " Validation failed for the below reasons!!<hr>" + helper.ValidationMessage;
                logger.LogWarn(helper.IdentityNumber + " Validation failed for the below reasons!!");
                logger.LogWarn(helper.ValidationMessage);
            }
            return(response);
        }
Exemple #2
0
        public async Task <IActionResult> Create([FromBody] ResidentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var resident = _mapper.Map <Resident>(viewModel);
                _residentRepository.Add(resident);
                await _unitOfWork.CompleteAsync();

                var result = _mapper.Map <ResidentViewModel>(resident);
                return(Ok(result));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }