Beispiel #1
0
        public async Task <ActionResult <RpAddCitizen> > AddCitizen([FromBody] RqAddCitizen rqAddCitizen)
        {
            try
            {
                if (!string.IsNullOrEmpty(rqAddCitizen.Citizen.Inn) && !ValidationsCollection.Validations.IsValidInnForIndividual(rqAddCitizen.Citizen.Inn))
                {
                    return(Json(ResponseHelper.ReturnBadRequest("Inn not valid")));
                }

                if (!string.IsNullOrEmpty(rqAddCitizen.Citizen.Snils) && !ValidationsCollection.Validations.IsValidSnils(StringConverter.GetNumbers(rqAddCitizen.Citizen.Snils)))
                {
                    return(Json(ResponseHelper.ReturnBadRequest("Snils not valid")));
                }


                var citizenSql = new CitizenSql();
                try
                {
                    citizenSql = CitizenConverter.FromApiV1ToSql(rqAddCitizen.Citizen);
                }
                catch (Exception exception)
                {
                    LoggerStatic.Logger.Warn("Exception: " + exception);
                    return(Json(ResponseHelper.ReturnBadRequest(exception.Message)));
                }

                var guid = await _peopleService.AddCitizen(citizenSql);

                var rpAddCitizen = new RpAddCitizen
                {
                    Guid = guid
                };
                return(Json(rpAddCitizen));
            }
            catch (Exception exception)
            {
                LoggerStatic.Logger.Error("Exception: " + exception);
                return(Json(ResponseHelper.ReturnInternalServerError(exception.Message)));
            }
        }