Пример #1
0
        /// <summary>
        /// Create Identifier
        /// </summary>
        /// <param name="context"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public ApiResponse <bool> CreateIdentifier(TestProjectDbContext context, CreateIdentifierViewModel model)
        {
            try
            {
                Person person = _repository.GetPersonbyId(context, model.PersonId);

                if (person == null)
                {
                    throw new ErrorException("Person Id is invalid");
                }
                var identifier = new Identifier()
                {
                    PersonId = person.Id,
                    Id       = Guid.NewGuid(),
                    Type     = model.Type,
                    Value    = model.Value
                };

                _repository.CreateIdentifier(context, identifier);
                return(ApiResponse <bool> .SuccessResult(true));
            }
            catch (Exception ex) when(ex is FailException || ex is ValidationException || ex is ArgumentException)
            {
                return(ApiResponse <bool> .ErrorResult(message : ex.Message, statusCode : HttpStatusCode.BadRequest));
            }
            catch (Exception ex) when(ex is ErrorException)
            {
                //LoggingManager.Error(ex.ToString());
                return(ApiResponse <bool> .ErrorResult(message : ex.Message));
            }
            catch (Exception ex)
            {
                //LoggingManager.Error(ex.ToString());
                return(ApiResponse <bool> .ErrorResult(message : ex.Message));
            }
        }