Example #1
0
        public async Task <IActionResult> Add([FromBody] TermsOfUseDto termsOfUseDto)
        {
            if (await termsOfUseRepository.GetTermsOfUse(termsOfUseDto.PublicId) != null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"TermsOfUse with this PublicId == {termsOfUseDto.PublicId} already exists"));
            }
            TermsOfUse termsOfUse = new TermsOfUse(termsOfUseDto.PublicId, termsOfUseDto.DocumentName);
            await termsOfUseRepository.Add(termsOfUse);

            await unitOfWork.SaveEntitiesAsync();

            return(Ok());
        }
Example #2
0
        public async Task <IActionResult> Update([FromBody] TermsOfUseDto termsOfUseDto)
        {
            TermsOfUse termsOfUse = await termsOfUseRepository.GetTermsOfUse(termsOfUseDto.Id);

            if (termsOfUse == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"TermsOfUse id == {termsOfUseDto.Id}. Not found!"));
            }
            if (termsOfUse.PublicId != termsOfUseDto.PublicId)
            {
                if (await termsOfUseRepository.GetTermsOfUse(termsOfUseDto.PublicId) != null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, $"TermsOfUse with this PublicId == {termsOfUseDto.PublicId} already exists"));
                }
                termsOfUse.SetPublicId(termsOfUseDto.PublicId);
            }
            termsOfUse.SetDocumentName(termsOfUseDto.DocumentName);
            await termsOfUseRepository.Update(termsOfUse);

            await unitOfWork.SaveEntitiesAsync();

            return(Ok());
        }