コード例 #1
0
        public async Task <IActionResult> UpdateAgreementTemplate(Entity.AgreementTemplate agreement)
        {
            if (this.UserInRole(Role.Manager) || this.UserInRole(Role.Admin))
            {
                var updatedTemplate = await _agreementTemplateRepository.UpdateAgreementTemplate(agreement);

                return(new ObjectResult(updatedTemplate));
            }
            else
            {
                var err = new DTO.ErrorBuilder()
                          .Message("You are not authorized to update agreement templates.")
                          .Code(403)
                          .Build();
                _logger.LogWarning($"Unauthorized access attempt to update agreement templates.");
                return(err);
            }
        }
コード例 #2
0
        public async Task <Entity.AgreementTemplate> UpdateAgreementTemplate(Entity.AgreementTemplate agreement)
        {
            var existingTemplate = await _context.AgreementTemplates
                                   .Where(a => a.AgreementTemplateId == agreement.AgreementTemplateId)
                                   .Select(a => a)
                                   .FirstOrDefaultAsync();

            if (existingTemplate == null)
            {
                await _context.AddAsync(agreement);

                await _context.SaveChangesAsync();

                return(agreement);
            }
            else
            {
                existingTemplate.Title = agreement.Title;
                existingTemplate.Title = agreement.Text;
                await _context.SaveChangesAsync();

                return(existingTemplate);
            }
        }