示例#1
0
        public async Task <ResultResponse <LegislationDto> > AddAsync(LegislationCreateDto createDto, int creatorId)
        {
            try
            {
                var creator = await _usersRepository.GetAsync(creatorId);

                if (creator == null)
                {
                    return(ResultResponse <LegislationDto> .GetBadResponse(StatusCode.NotFound, "Пользователь с таким идентификатором не найден"));
                }
                var legislation = _mapper.Map <Legislation>(createDto);
                legislation.creator_id = creatorId;
                legislation.created    = DateTime.Now;
                var added = await _legislationsRepository.AddAsync(legislation);

                if (added == null)
                {
                    return(ResultResponse <LegislationDto> .GetInternalServerErrorResponse());
                }
                var newLegislationDto = _mapper.Map <LegislationDto>(added);
                return(ResultResponse <LegislationDto> .GetSuccessResponse(newLegislationDto));
            }
            catch (Exception ex)
            {
                _progressLogger.Error(ex, new { createDto, creatorId }, GetType().Name, nameof(AddAsync));
                return(ResultResponse <LegislationDto> .GetInternalServerErrorResponse());
            }
        }
示例#2
0
 public async Task <ResultResponse <LegislationDto> > AddLegislation([FromBody] LegislationCreateDto createDto)
 {
     if (await IsInRole(Roles.Admin))
     {
         return(await _legislationService.AddAsync(createDto, UserId.Value));
     }
     return(ResultResponse <LegislationDto> .GetBadResponse(BussinesLogic.Models.StatusCode.Forbidden));
 }