示例#1
0
        public ApplicationUserDTO Create(ApplicationUserDTO user, string password)
        {
            if (_userRepository.GetAll().Any(u => u.Email == user.Email))
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.UnprocessableEntity, "Such user already exists");
            }

            user.SettingsId = _settingsRepository.GetSettingsByPhoneId(user.PhoneIdentifier).SettingsId;
            user.Id         = _userRepository.GetAll().First(u => u.PhoneIdentifier == user.PhoneIdentifier).AccountId;

            _userRepository.UpdateUser(new ApplicationUserModel
            {
                City             = user.City,
                Country          = user.Country,
                DateOfBirth      = Convert.ToDateTime(user.DateOfBirth).Date,
                Email            = user.Email,
                FirstName        = user.FirstName,
                Id               = user.Id,
                LastName         = user.LastName,
                PasswordHash     = PasswordGenerators.CreatePasswordHash(password),
                SettingsId       = user.SettingsId.Value,
                PhoneNumber      = user.PhoneNumber,
                PhoneIdentifier  = user.PhoneIdentifier,
                ValidationCode   = user.ValidationCode,
                CodeCreationTime = user.CodeCreationTime
            });

            _theaterScheduleUnitOfWork.Save();

            return(user);
        }
示例#2
0
        public UrlDTO Add(UrlDTO link)
        {
            _formUrlRepository.Add(new UrlModel
            {
                UrlId = link.UrlId,
                Url   = link.Url
            });

            _theaterScheduleUnitOfWork.Save();

            return(link);
        }
        public void StoreSettings(string phoneId, SettingsDTO settingsRequest)
        {
            Language language = languageRepository.GetLanguageByName(settingsRequest.LanguageCode);

            if (language == null)
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound,
                          $"Language [{settingsRequest.LanguageCode}] doesn't exist");
            }

            NotificationFrequency notificationFrequency =
                notificationFrequencyRepository.GetNotificationFrequencyByFrequency(settingsRequest.NotificationFrequency);

            if (notificationFrequency == null)
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound,
                          $"Notification frequency [{settingsRequest.NotificationFrequency}] doesn't exist");
            }

            Entities.Models.Settings settings = settingsRepository.GetSettingsByPhoneId(phoneId);
            if (settings != null)
            {
                settings.Language              = language;
                settings.DoesNotify            = settingsRequest.DoesNotify;
                settings.NotificationFrequency = notificationFrequency;
            }
            else
            {
                Entities.Models.Settings newSettings = new Entities.Models.Settings
                {
                    Language              = language,
                    DoesNotify            = true,
                    NotificationFrequency = notificationFrequency
                };

                settingsRepository.Add(newSettings);

                accountRepository.Add(new Account
                {
                    PhoneIdentifier = phoneId,
                    Settings        = newSettings,
                    PasswordHash    = "",
                    Email           = phoneId,
                    FirstName       = "",
                    City            = ""
                });
            }
            theaterScheduleUnitOfWork.Save();
        }
示例#4
0
        public void SendMessage(MessageDTO newMessage)
        {
            var account = userRepository.GetById(newMessage.AccountId);

            if (account == null)
            {
                throw new NullReferenceException("account");
            }

            var message = _mapper.Map <Message>(newMessage);

            messageRepository.Add(message);
            theaterScheduleUnitOfWork.Save();
        }
        public void StorePushToken(string phoneId, string pushToken)
        {
            Account account = accountRepository.GetAccountByPhoneId(phoneId);

            if (account == null)
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound, $"Account [{phoneId}] doesn't exist");
            }
            else
            {
                PushToken newToken = new PushToken {
                    Token = pushToken, Account = account
                };
                pushTokenRepository.Add(newToken);
            }
            theaterScheduleUnitOfWork.Save();
        }
        public async Task SaveOrDeletePerformance(string AccountId, int performanceId)
        {
            Entities.Models.Wishlist performance = await
                                                   WishlistRepository.GetPerformanceByPhoneIdAndPerformanceId(
                AccountId, performanceId);

            if (performance == null)
            {
                performance = new Entities.Models.Wishlist()
                {
                    AccountId     = int.Parse(AccountId),
                    PerformanceId = performanceId
                };
                WishlistRepository.Add(performance);
            }
            else
            {
                WishlistRepository.Remove(performance);
            }

            theaterScheduleUnitOfWork.Save();
        }
示例#7
0
 public void AddNewPost(AdminsPostDTO post)
 {
     adminsPostRepository.Add(mapper.Map <AdminsPostDTO, AdminsPost>(post));
     theaterScheduleUnitOfWork.Save();
 }