Exemplo n.º 1
0
        public async Task <NewsForReturnDto> Create(NewsForCreationDto creationDto)
        {
            var checkByNameFromRepo = await newsDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower());

            if (checkByNameFromRepo != null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist });
            }

            var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);

            var mapForCreate = mapper.Map <News>(creationDto);
            var slideId      = Guid.NewGuid();

            mapForCreate.SlideId      = slideId;
            mapForCreate.UserId       = claimId;
            mapForCreate.Created      = DateTime.Now;
            mapForCreate.AnnounceType = "news";

            var createNews = await newsDal.Add(mapForCreate);

            var spec = new NewsWithUserSpecification(createNews.Id);

            var getNewsFromRepo = await newsDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <News, NewsForReturnDto>(getNewsFromRepo));
        }
 public void Add(News data)
 {
     _context.Add(data);
 }
Exemplo n.º 3
0
 public void Add(Entities.News entity)
 {
     _newsDal.Add(entity);
 }
Exemplo n.º 4
0
 public void Add(News news)
 {
     ValidationTool.Validate(new NewsValidator(), news);
     _newsDal.Add(news);
 }