Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="model"></param>
        public ApiResponse <bool> UpdatePerson(TestProjectDbContext context, PersonUpdateViewModel model)
        {
            Person person = _repository.GetPersonbyId(context, model.PersonId);

            if (person == null)
            {
                throw new ErrorException("Person Id is invalid");
            }
            try
            {
                person.FirstName = model.FirstName;
                person.LastName  = model.LastName;
                _repository.UpdatePerson(context, person);

                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));
            }
        }