public async Task <AnnounceForKiosksToReturnDto> GetAnnounceByIdAsync(int announceId) { var spec = new AnnounceWithUserSpecification(announceId); var announce = await announceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <Announce, AnnounceForKiosksToReturnDto>(announce)); }
public async Task <AnnounceForReturnDto> Create(AnnounceForCreationDto creationDto) { var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value); var checkByNameFromRepo = await announceDal.GetAsync(x => x.Header.ToLower() == creationDto.Header.ToLower()); if (checkByNameFromRepo != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var mapForCreate = mapper.Map <Announce>(creationDto); var slideId = Guid.NewGuid(); mapForCreate.SlideId = slideId; if (creationDto.UserId > 0) { mapForCreate.UserId = creationDto.UserId; } else { mapForCreate.UserId = claimId; } mapForCreate.Created = DateTime.Now; mapForCreate.AnnounceType = "announce"; var createAnnounce = await announceDal.Add(mapForCreate); var spec = new AnnounceWithUserSpecification(createAnnounce.Id); var getAnnounceFromRepo = await announceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceFromRepo)); }
public async Task <AnnounceForReturnDto> Update(AnnounceForCreationDto updateDto) { var checkFromRepo = await announceDal.GetAsync(x => x.Id == updateDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var mapForUpdate = mapper.Map(updateDto, checkFromRepo); mapForUpdate.Updated = DateTime.Now; mapForUpdate.AnnounceType = "announce"; await announceDal.Update(mapForUpdate); var spec = new AnnounceWithUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await announceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceWithUserFromRepo)); }
public async Task <AnnounceForReturnDto> Publish(AnnounceForCreationDto updateDto) { var checkFromRepo = await announceDal.GetAsync(x => x.Id == updateDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var checkHomeAnnounceSubScreenForPublish = await announceSubScreenDal.GetListAsync(x => x.AnnounceId == updateDto.Id); if (checkHomeAnnounceSubScreenForPublish.Count <= 0) { throw new RestException(HttpStatusCode.BadRequest, new { NotSelectSubScreen = Messages.NotSelectSubScreen }); } if (updateDto.IsPublish) { var checkDateExpire = DateTime.Compare(DateTime.Now, checkFromRepo.PublishFinishDate); if (checkDateExpire > 0) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.PublishDateExpire }); } } var mapForUpdate = mapper.Map(updateDto, checkFromRepo); mapForUpdate.Updated = DateTime.Now; mapForUpdate.AnnounceType = "announce"; await announceDal.Update(mapForUpdate); var spec = new AnnounceWithUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await announceDal.GetEntityWithSpecAsync(spec); return(mapper.Map <Announce, AnnounceForReturnDto>(getAnnounceWithUserFromRepo)); }