Пример #1
0
        public async Task <ViewModels.ApplicationTemplate> CreateTemplateAsync(ViewModels.ApplicationTemplateForm form, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded)
            {
                throw new ForbiddenException();
            }

            var templateEntity = Mapper.Map <ApplicationTemplateEntity>(form);

            _context.ApplicationTemplates.Add(templateEntity);
            await _context.SaveChangesAsync(ct);

            return(Mapper.Map <ViewModels.ApplicationTemplate>(templateEntity));
        }
Пример #2
0
        public async Task <ViewModels.ApplicationTemplate> UpdateTemplateAsync(Guid id, ViewModels.ApplicationTemplateForm form, CancellationToken ct)
        {
            if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded)
            {
                throw new ForbiddenException();
            }

            var templateToUpdate = await _context.ApplicationTemplates.SingleOrDefaultAsync(v => v.Id == id, ct);

            if (templateToUpdate == null)
            {
                throw new EntityNotFoundException <ApplicationTemplate>();
            }

            Mapper.Map(form, templateToUpdate);

            _context.ApplicationTemplates.Update(templateToUpdate);
            await _context.SaveChangesAsync(ct);

            return(await GetTemplateAsync(templateToUpdate.Id, ct));
        }