コード例 #1
0
        public async Task <UserDTO> EditUserInfo(UserEditDTO userInfo)
        {
            using (_unitOfWork)
            {
                User user = await _unitOfWork.UserRepository.FindByID(userInfo.UserId);

                user.Name     = userInfo.Name;
                user.LastName = userInfo.LastName;
                if (!string.IsNullOrEmpty(userInfo.Picture))
                {
                    user.Picture = PictureManagerService.SaveImageToFile(userInfo.Picture, user.GetType().Name, user.UserId);
                }

                _unitOfWork.UserRepository.Update(user);
                await _unitOfWork.Save();

                if (userInfo.Picture != null)
                {
                    user.Picture = null;
                }

                UserDTO returnUser = _mapper.Map <User, UserDTO>(user);

                if (userInfo.Picture != null)
                {
                    returnUser.Picture = userInfo.Picture;
                }

                return(returnUser);
            }
        }
コード例 #2
0
        public async Task <AccommodationPictureDTO> AddAccommodationPicture(AccommodationPictureCreateDTO picture)
        {
            using (_unitOfWork)
            {
                Accommodation accommodation = await _unitOfWork.AccommodationRepository.GetAccommodationWithLocation(picture.AccommodationId);

                AccommodationPicture accommodationPicture = new AccommodationPicture
                {
                    AccommodationPictureId = 0,
                    AccommodationId        = accommodation.AccommodationId,
                    Accommodation          = accommodation,
                    Picture = "temp",
                };

                await _unitOfWork.AccommodationPictureRepository.Create(accommodationPicture);

                await _unitOfWork.Save();

                accommodationPicture.Picture       = PictureManagerService.SaveImageToFile(picture.Picture, accommodation.GetType().Name, accommodationPicture.AccommodationPictureId);
                accommodationPicture.Accommodation = accommodation;

                if (accommodation.Pictures == null)
                {
                    accommodation.Pictures = new List <AccommodationPicture>();
                }
                accommodation.Pictures.Add(accommodationPicture);
                _unitOfWork.AccommodationPictureRepository.Update(accommodationPicture);
                await _unitOfWork.Save();

                accommodationPicture.Picture = null;

                AccommodationPictureDTO res = _mapper.Map <AccommodationPicture, AccommodationPictureDTO>(accommodationPicture);
                res.Picture = picture.Picture;
                await _messageControllerService.NotifyOnTripChanges(accommodation.Location.TripId, "AddAccommodationPicture", res);

                return(res);
            }
        }