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); }
public async Task <NotifyGroupForReturnDto> Create(NotifyGroupForCreationDto createDto) { var checkByName = await notifyGroupDal.GetAsync(x => x.GroupName.ToLower() == createDto.GroupName.ToLower()); if (checkByName != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var mapForCreate = mapper.Map <NotifyGroup>(createDto); var saveToDb = await notifyGroupDal.Add(mapForCreate); var mapForReturn = mapper.Map <NotifyGroup, NotifyGroupForReturnDto>(saveToDb); return(mapForReturn); }