Exemple #1
0
        public async Task ReloadAsync(Func <string, string> pathGetter)
        {
            await dbContext.Tours.LoadAsync();

            allServices = dbContext.Tours.AsNoTracking().ToList();

            allServicesDto = allServices.Select(x =>
            {
                var t       = mapper.MapTo <Tour, TourDto>(x);
                t.ImagePath = pathGetter?.Invoke(t.ImageName);
                return(t);
            });
        }
        public async Task ReloadAsync(ValuteGetterService valuteGetter)
        {
            await dbContext.Insurances.LoadAsync();

            _insurances = await dbContext.Insurances.AsNoTracking().ToListAsync();

            _insurancesDto = _insurances.Select(x =>
            {
                var dto     = mapper.MapTo <Insurance, InsuranceDto>(x);
                dto.CostUSD = valuteGetter.GetUSDValue(x.Cost);
                dto.CostEUR = valuteGetter.GetEuroValue(x.Cost);
                return(dto);
            }).ToList();
        }
Exemple #3
0
        /// <summary>
        /// Returns a user, whoose phone and pass are equial to input params, otherwise - null
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public async Task <ProfileDto> LoginAsync(string phone, string pass)
        {
            await dbContext.Profiles.LoadAsync();

            var profile = await dbContext.
                          Profiles.
                          FirstOrDefaultAsync(x => string.Compare(x.PhoneNumber, phone) == 0 && string.Compare(x.Password, pass) == 0);

            if (profile != null)
            {
                return(mapper.MapTo <Profile, ProfileDto>(profile));
            }

            return(null);
        }
        public async Task <ProfileDto> GetProfile()
        {
            if (!IsAutorized)
            {
                return(null);
            }

            await dbContext.Profiles.LoadAsync();

            var profile = await dbContext.Profiles.FindAsync(CurrentUser.Id);

            if (profile != null)
            {
                return(mapper.MapTo <Profile, ProfileDto>(profile));
            }

            return(null);
        }
Exemple #5
0
        public async Task <bool> Login(string login, string pass)
        {
            await dbContext.Profiles.Include(x => x.Client).LoadAsync();

            var user = await dbContext.
                       Profiles.
                       FirstOrDefaultAsync(x => string.Compare(x.Login, login) == 0 && string.Compare(x.Password, pass) == 0);

            if (user != null)
            {
                var dto = mapper.MapTo <Client, ClientDto>(user.Client);
                userService.SetupUser(dto);
                return(true);
            }
            ErrorMessage = "Неправильные логин или пароль";

            return(false);
        }
Exemple #6
0
        /// <summary>
        /// УСТАНОВКА КАК ТЕКЩУЕГО ПОЛЬЗОВАТЕЛЯ НЕ ПРОИЗВОДИТСЯ
        /// </summary>
        /// <returns></returns>

        public async Task <int> RegisterAsync(bool setupUser = true)
        {
            if (_curProfile == null)
            {
                throw new ArgumentException("Профиль не был загружен");
            }


            await db.Profiles.LoadAsync();

            if (await db.Profiles.FirstOrDefaultAsync(x => x.Password == _passw) != null)
            {
                ErrorMessage = "Такой пароль уже есть";
                return(-1);
            }

            Profile profile = mapper.MapTo <ProfileDto, Profile>(_curProfile);

            profile.Password = _passw;
            db.Profiles.Add(profile);

            try
            {
                await db.SaveChangesAsync();

                if (setupUser)
                {
                    _curProfile.Id = profile.Id;
                    userService.SetupUser(_curProfile);
                }

                return(profile.Id);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(-1);
            }
        }