/// <inheritdoc />
        public async Task <MementoResponse> UpdateAsync(long personId, PersonFormContract person)
        {
            // Invoke the API
            var response = await this.HttpService.PutAsync($"{API_URL}{personId}", person);

            if (!response.Success)
            {
                throw new ApplicationException(string.Join(Environment.NewLine, response.Errors));
            }
            else
            {
                return(response);
            }
        }
        /// <inheritdoc />
        public async Task <MementoResponse <PersonDetailContract> > CreateAsync(PersonFormContract person)
        {
            // Invoke the API
            var response = await this.HttpService.PostAsync <PersonFormContract, PersonDetailContract>($"{API_URL}", person);

            if (!response.Success)
            {
                throw new ApplicationException(string.Join(Environment.NewLine, response.Errors));
            }
            else
            {
                return(response);
            }
        }
Пример #3
0
        public async Task <ActionResult <MementoResponse <PersonDetailContract> > > CreateAsync([FromBody] PersonFormContract contract)
        {
            // Check if there's a picture in the contract
            if (contract.Picture == null)
            {
                // Get the field name
                var name = this.Localizer.GetString(SharedResources.PERSON_PICTURE);

                // Create the message with the given context
                var message = this.Localizer.GetString(SharedResources.ERROR_INVALID_FIELD, name);

                // Throw an exception due to the missing picture
                throw new MementoException(message, MementoExceptionType.BadRequest);
            }

            // Map the person
            var person = this.Mapper.Map <Person>(contract);

            // Create the picture in the storage
            person.PictureUrl = await this.Storage.CreateAsync(contract.Picture.FileBase64, contract.Picture.FileName);

            // Create the person
            var createdPerson = await this.Repository.CreateAsync(person);

            // Build the response
            return(this.BuildCreateResponse <Person, PersonDetailContract>(createdPerson));
        }
Пример #4
0
        public async Task <ActionResult <MementoResponse> > UpdateAsync([FromRoute] long id, [FromBody] PersonFormContract contract)
        {
            // Map the person
            var person = this.Mapper.Map <Person>(contract);

            person.Id = id;

            // Check if there's a picture in the contract
            if (contract.Picture != null)
            {
                // Create the picture in the storage
                person.PictureUrl = await this.Storage.CreateAsync(contract.Picture.FileBase64, contract.Picture.FileName);
            }
            else
            {
                person.PictureUrl = (await this.Repository.GetAsync(id)).PictureUrl;
            }

            // Update the person
            await this.Repository.UpdateAsync(person);

            // Build the response
            return(this.BuildUpdateResponse());
        }