public async Task <UserNotifyGroupForReturnDto> Update(UserNotifyGroupForCreationDto updateDto)
        {
            var userFromRepo = await userDal.GetAsync(x => x.Id == updateDto.UserId);

            if (userFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { UserNotFound = "Kullanıcı bulunamadı.." });
            }

            var notifyGroupFromRepo = await notifyGroupDal.GetAsync(x => x.Id == updateDto.Id);

            if (notifyGroupFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { UserNotFound = "Bildirim Gurubu bulunamadı..." });
            }

            var checkById = await userNotifyGroupDal.GetAsync(x => x.Id == updateDto.Id);

            if (checkById == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound });
            }

            var mapForUpdate = mapper.Map(updateDto, checkById);
            await userNotifyGroupDal.Update(mapForUpdate);

            var spec = new UserNotifyGroupWithNotifyGroupSpecification();
            var getUserNotifyGroup = await userNotifyGroupDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <UserNotifyGroup, UserNotifyGroupForReturnDto>(getUserNotifyGroup));
        }
        public async Task <UserNotifyGroupForReturnDto> Create(UserNotifyGroupForCreationDto createDto)
        {
            var userFromRepo = await userDal.GetAsync(x => x.Id == createDto.UserId);

            if (userFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { UserNotFound = "Kullanıcı bulunamadı.." });
            }

            var notifyGroupFromRepo = await notifyGroupDal.GetAsync(x => x.Id == createDto.NotifyGroupId);

            if (notifyGroupFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { UserNotFound = "Bildirim Gurubu bulunamadı..." });
            }
            var checkByName = await userNotifyGroupDal.GetAsync(x => x.UserId == createDto.UserId && x.NotifyGroupId == createDto.NotifyGroupId);

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

            var mapForCreate = mapper.Map <UserNotifyGroup>(createDto);
            var saveToDb     = await userNotifyGroupDal.Add(mapForCreate);

            var spec = new UserNotifyGroupWithByNotifyGroupId(saveToDb.NotifyGroupId);
            var getUserNotifyGroup = await userNotifyGroupDal.GetEntityWithSpecAsync(spec);

            var mapForReturn = mapper.Map <UserNotifyGroup, UserNotifyGroupForReturnDto>(getUserNotifyGroup);

            return(mapForReturn);
        }
Пример #3
0
 public async Task <ActionResult <UserNotifyGroupForReturnDto> > Update(UserNotifyGroupForCreationDto updateDto)
 {
     return(await userNotifyService.Update(updateDto));
 }