Beispiel #1
0
        public async Task <CommonResult> UpdateCoverAsync(ClaimsPrincipal claimsPrincipal, UserPhotoUpdateModel criterias)
        {
            try
            {
                if (!criterias.CanEdit)
                {
                    throw new UnauthorizedAccessException();
                }

                var currentUserId = GetCurrentUserId(claimsPrincipal);
                var result        = await _userPhotoService.UpdateUserPhotoAsync(new UserPhotoUpdateRequest
                {
                    PhotoUrl        = criterias.PhotoUrl,
                    FileName        = criterias.FileName,
                    Width           = criterias.Width,
                    Height          = criterias.Height,
                    Scale           = criterias.Scale,
                    XAxis           = criterias.XAxis,
                    YAxis           = criterias.YAxis,
                    UserPhotoTypeId = (int)UserPictureType.Cover
                }, currentUserId);

                return(CommonResult.Success(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task <CommonResult> ForgotPasswordAsync(ForgotPasswordModel criterias)
        {
            ValidateForgotPassword(criterias);

            var user = await _userManager.FindByEmailAsync(criterias.Email);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
            {
                throw new CaminoApplicationException("ForgotPasswordConfirmation");
            }

            var resetPasswordToken = await _userManager.GeneratePasswordResetTokenAsync(user);

            var result = await _userManager.SetAuthenticationTokenAsync(user, ServiceProvidersNameConst.CAMINO_API_AUTH, IdentitySettings.RESET_PASSWORD_PURPOSE, resetPasswordToken);

            if (!result.Succeeded)
            {
                var errors = result.Errors.Select(x => new CommonError
                {
                    Message = x.Description,
                    Code    = x.Code
                });
                return(CommonResult.Failed(errors));
            }

            await SendPasswordChangeAsync(criterias, user, resetPasswordToken);

            return(CommonResult.Success());
        }
Beispiel #3
0
        public async Task <CommonResult> ResetPasswordAsync(ResetPasswordModel criterias)
        {
            ValidateResetPassword(criterias);
            var user = await _userManager.FindByEmailAsync(criterias.Email);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
            {
                throw new UnauthorizedAccessException("ResetPasswordFailed");
            }

            var result = await _userManager.ResetPasswordAsync(user, criterias.Key, criterias.Password);

            if (!result.Succeeded)
            {
                var errors = result.Errors.Select(x => new CommonError()
                {
                    Message = x.Description,
                    Code    = x.Code
                });

                return(CommonResult.Failed(errors));
            }
            await _userManager.RemoveAuthenticationTokenAsync(user, ServiceProvidersNameConst.CAMINO_API_AUTH, criterias.Key);

            return(CommonResult.Success());
        }
Beispiel #4
0
        public async Task <CommonResult> Add(UserRatingDto ratingDto)
        {
            if (string.IsNullOrEmpty(ratingDto.Feedback))
            {
                return(CommonResult.Failure("Cannot create user without field provided."));
            }

            if (string.IsNullOrEmpty(ratingDto.UserAssessorId))
            {
                return(CommonResult.Failure("Cannot create user without userAssessorId provided."));
            }

            if (string.IsNullOrEmpty(ratingDto.UserEvaluatedId))
            {
                return(CommonResult.Failure("Cannot create user without userEvaluatedId provided."));
            }

            if (Enum.IsDefined(typeof(StarNumberType), ratingDto.StarType))
            {
                return(CommonResult.Failure("Wrong enum value."));
            }


            await _ratingsRepository.Add(ratingDto);

            return(CommonResult.Success());
        }
Beispiel #5
0
        public async Task <ActionResult> Login([FromBody] BKLoginInfo loginInfo)
        {
            if (HttpContext.Session.GetString("user") != null)
            {
                return(Ok(CommonResult.Fail("already login")));
            }
            BkUser user = await _userReposity.GetUserByAccount(loginInfo.Account);

            if (user == null)
            {
                return(Ok(CommonResult.Fail("e - mail address don't exist")));
            }
            if (await _userInfoReposity.GetState(user.UId) == 0)
            {
                return(Ok(CommonResult.Fail("you have been banned, please contact administrator first")));
            }
            if (user.Password == MD5Util.GenerateMD5(loginInfo.Password, user.Salt))
            {
                HttpContext.Session.SetString("user", user.Account);
                return(Ok(CommonResult.Success(user.Account)));
            }
            else
            {
                return(Ok(CommonResult.Fail("password error")));
            }
        }
Beispiel #6
0
        /*----------------------*/
        public CommonResult <IEnumerable <LocationFormDto> > ShowBarsInformaiton(string sortOrder, string searchString = null)
        {
            if (_db.Locations.Count() == 0)
            {
                return(CommonResult <IEnumerable <LocationFormDto> >
                       .Failure <IEnumerable <LocationFormDto> >
                           ("The DB does not contain any location yet..."));
            }

            var adapter = new SqlDataAdapter();
            var con     = new SqlConnection();

            con.ConnectionString = ConnectionString;
            var select = new SqlCommand("SELECT Id, Name, Address, Latitude, Longitude" +
                                        " FROM Locations", con);

            //    select.Parameters.AddWithValue("@Name", searchString);
            adapter.SelectCommand = select;

            var ds = new DataSet();

            adapter.Fill(ds, "Locations");
            var table = ds.Tables[0];
            var data  = _sorting.Mapping(table, searchString).ToList();

            return(CommonResult <IEnumerable <LocationFormDto> >
                   .Success(_sorting.SortByQuery(data
                                                 , sortOrder)));
        }
Beispiel #7
0
        public CommonResult <IQueryable <DrinksInfoDto> > GetDrinksList()
        {
            IQueryable <DrinksInfoDto> DrinksList;

            if (_db.Drinks.Any())
            {
                return(CommonResult <IQueryable <DrinksInfoDto> >
                       .Failure <IQueryable <DrinksInfoDto> >("No drinks Yet..."));
            }

            try
            {
                DrinksList = from a in _db.Drinks
                             join b in _db.Locations
                             on a.LocationOfDrinkId equals b.Id
                             join c in _db.DrinkTypes
                             on a.DrinkTypeId equals c.Id
                             select new DrinksInfoDto
                {
                    Name     = a.Name,
                    Price    = a.Price,
                    Type     = c.Name,
                    Location = b.Name
                };
            }
            catch (Exception ex)
            {
                return(CommonResult <IQueryable <DrinksInfoDto> >
                       .Failure <IQueryable <DrinksInfoDto> >("Something Wrong with Db" + ex.Message));
            }

            return(CommonResult <IQueryable <DrinksInfoDto> >
                   .Success(DrinksList));
        }
Beispiel #8
0
        public async Task <CommonResult> ActiveAsync(ActiveUserModel criterias)
        {
            var user = await _userManager.FindByNameAsync(criterias.Email);

            if (!await _userManager.IsEmailConfirmedAsync(user))
            {
                var result = await _userManager.ConfirmEmailAsync(user, criterias.ActiveKey);

                if (result.Succeeded)
                {
                    return(CommonResult.Success());
                }

                var errors = result.Errors.Select(x => new CommonError()
                {
                    Message = x.Description,
                    Code    = x.Code
                });

                return(CommonResult.Failed(errors));
            }

            return(CommonResult.Failed(new CommonError()
            {
                Message = "The user is already confirmed"
            }));
        }
Beispiel #9
0
        public async Task <CommonResult <UserWorkPhotoDto> > GetById(int id)
        {
            var photoDto = await _photosOfWorkRepository.GetById(id);

            if (photoDto == null)
            {
                return(CommonResult <UserWorkPhotoDto> .Failure <UserWorkPhotoDto>("Problem occured during fetching photo url with given id."));
            }
            return(CommonResult <UserWorkPhotoDto> .Success(photoDto));
        }
Beispiel #10
0
        public async Task <CommonResult <ExperianceDto> > GetById(int id)
        {
            var person = await _experiancesRepository.GetById(id);

            if (person == null)
            {
                return(CommonResult <ExperianceDto> .Failure <ExperianceDto>("Problem occured during fetching project with given id."));
            }
            return(CommonResult <ExperianceDto> .Success(person));
        }
Beispiel #11
0
        public async Task <CommonResult <QualificationDto> > GetUser(int id)
        {
            var person = await _qualificationsRepository.GetById(id);

            if (person == null)
            {
                return(CommonResult <QualificationDto> .Failure <QualificationDto>("Problem occured during fetching qualification with given id."));
            }
            return(CommonResult <QualificationDto> .Success(person));
        }
        public async Task <CommonResult <ApplicationUserDto> > GetUser(string id)
        {
            var person = await _personRepository.GetUser(id);

            if (person == null || person.IsDeleted)
            {
                return(CommonResult <ApplicationUserDto> .Failure <ApplicationUserDto>("Problem occured during fetching project with given id."));
            }
            return(CommonResult <ApplicationUserDto> .Success(person));
        }
Beispiel #13
0
        public async Task <CommonResult> Update(UserWorkPhotoDto photoDto)
        {
            var updateApplicationUserDto = await _photosOfWorkRepository.Update(photoDto);

            if (updateApplicationUserDto == null)
            {
                return(CommonResult <UserWorkPhotoDto> .Failure <UserWorkPhotoDto>("Problem occured updating entity."));
            }

            return(CommonResult <UserWorkPhotoDto> .Success(photoDto));
        }
        public async Task <CommonResult> Update(ApplicationUserDto user)
        {
            var updateApplicationUserDto = await _personRepository.UpdateUser(user);

            if (updateApplicationUserDto == null || updateApplicationUserDto.IsDeleted)
            {
                return(CommonResult <ApplicationUserDto> .Failure <ApplicationUserDto>("Problem occured updating entity."));
            }

            return(CommonResult <ApplicationUserDto> .Success(user));
        }
Beispiel #15
0
        public async Task <CommonResult> Update(QualificationDto qualificationDto)
        {
            var updateQualificationDto = await _qualificationsRepository.Update(qualificationDto);

            if (updateQualificationDto == null)
            {
                return(CommonResult <QualificationDto> .Failure <QualificationDto>("Problem occured updating entity."));
            }

            return(CommonResult <QualificationDto> .Success(qualificationDto));
        }
Beispiel #16
0
        public async Task <CommonResult> Update(ExperianceDto experianceDto)
        {
            var updateExperianceDto = await _experiancesRepository.Update(experianceDto);

            if (updateExperianceDto == null)
            {
                return(CommonResult <ExperianceDto> .Failure <ExperianceDto>("Problem occured updating entity."));
            }

            return(CommonResult <ExperianceDto> .Success(experianceDto));
        }
Beispiel #17
0
        public async Task <CommonResult> Add(ExperianceDto experianceDto)
        {
            if (await CheckIfExperianceAlreadyExist(experianceDto.UserId, experianceDto.ExperianceType))
            {
                return(CommonResult.Failure("This experiance User already has"));
            }

            await _experiancesRepository.Add(experianceDto);

            return(CommonResult.Success());
        }
Beispiel #18
0
        public CommonResult <ProjectDto> GetById(int id)
        {
            var project = _projectsRepository.GetById(id);

            if (project == null || project.IsDeleted)
            {
                return(CommonResult <ProjectDto> .Failure <ProjectDto>("Problem occured during fetching project with given id."));
            }
            else
            {
                return(CommonResult <ProjectDto> .Success <ProjectDto>(project));
            }
        }
Beispiel #19
0
        public CommonResult <IEnumerable <LocationFeedbackDto> > GetFeedbackList(int id)
        {
            IEnumerable <LocationFeedbackDto> loc = _db.LocationFeedbacks.Where(a => a.LocationId == id).Select(a => new LocationFeedbackDto
            {
                Id         = a.Id,
                LocationId = a.LocationId,
                Feedback   = a.Feedback,
                User       = a.User
            });


            return(CommonResult <IEnumerable <LocationFeedbackDto> >
                   .Success <IEnumerable <LocationFeedbackDto> >(loc));
        }
Beispiel #20
0
        public async Task <CommonResult> Add(UserWorkPhotoDto experianceDto)
        {
            if (string.IsNullOrEmpty(experianceDto.ApplicationUserId))
            {
                return(CommonResult.Failure("Empty user Id"));
            }

            if (string.IsNullOrEmpty(experianceDto.PhotoUrl))
            {
                return(CommonResult.Failure("Cannot create photo without its url address"));
            }

            await _photosOfWorkRepository.Add(experianceDto);

            return(CommonResult.Success());
        }
Beispiel #21
0
        public async Task <CommonResult> Add(QualificationDto qualificationDto)
        {
            if (string.IsNullOrEmpty(qualificationDto.QualificationField))
            {
                return(CommonResult.Failure("Cannot create user without field provided."));
            }

            if (string.IsNullOrEmpty(qualificationDto.ApplicationUserId))
            {
                return(CommonResult.Failure("Cannot create user without user Id provided."));
            }

            await _qualificationsRepository.Add(qualificationDto);

            return(CommonResult.Success());
        }
Beispiel #22
0
        public async Task <CommonResult> SignupAsync(SignupModel criterias)
        {
            var user = new ApplicationUser()
            {
                BirthDate   = criterias.BirthDate,
                DisplayName = $"{criterias.Lastname} {criterias.Firstname}",
                Email       = criterias.Email,
                Firstname   = criterias.Firstname,
                Lastname    = criterias.Lastname,
                GenderId    = (byte)criterias.GenderId,
                StatusId    = (byte)UserStatus.Pending,
                UserName    = criterias.Email,
            };

            try
            {
                var result = await _userManager.CreateAsync(user, criterias.Password);

                if (result.Succeeded)
                {
                    user = await _userManager.FindByNameAsync(user.UserName);

                    var confirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    await SendActiveEmailAsync(user, confirmationToken);
                }
                else
                {
                    return(CommonResult.Failed(result.Errors.Select(x => new CommonError()
                    {
                        Code = x.Code,
                        Message = x.Description
                    })));
                }

                return(CommonResult.Success());
            }
            catch (Exception ex)
            {
                return(CommonResult.Failed(new CommonError()
                {
                    Message = ex.Message
                }));
            }
        }
Beispiel #23
0
        public async Task <CommonResult> DeleteAvatarAsync(ClaimsPrincipal claimsPrincipal, PhotoDeleteModel criterias)
        {
            try
            {
                if (!criterias.CanEdit)
                {
                    throw new UnauthorizedAccessException();
                }

                var currentUserId = GetCurrentUserId(claimsPrincipal);
                await _userPhotoService.DeleteUserPhotoAsync(currentUserId, UserPictureType.Avatar);

                return(CommonResult.Success(new UserPhotoUpdateRequest()));
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #24
0
        public CommonResult Add(AddProjectDto project)
        {
            if (string.IsNullOrEmpty(project.Name))
            {
                return(CommonResult.Failure("Cannot create project without name provided"));
            }
            if (string.IsNullOrEmpty(project.Description))
            {
                return(CommonResult.Failure("Cannot create project without description provided"));
            }
            var existingProject = _projectRepository.GetByName(project.Name);

            if (existingProject != null && existingProject.IsDeleted == false && existingProject.Name == project.Name)
            {
                return(CommonResult.Failure("Project name already exists"));
            }
            _projectRepository.Add(project);
            return(CommonResult.Success());
        }
Beispiel #25
0
        public CommonResult Add(DrinkDto item)
        {
            if (string.IsNullOrEmpty(item.Name))
            {
                return(CommonResult.Failure("No Name is declared"));
            }
            if (item.Price <= 0)
            {
                return(CommonResult.Failure("Price is not declared or less or equal then zero!"));
            }

            if (item.DrinkTypeId <= 0 || item.LocationOfDrinkId <= 0)
            {
                return(CommonResult.Failure("Wrong data with dropdown element"));
            }

            _repository.Add(item);

            return(CommonResult.Success());
        }
        public CommonResult Add(AddProjectDto project)
        {
            if (String.IsNullOrWhiteSpace(project.Name))
            {
                return(CommonResult.Failure("Project name is empty."));
            }
            if (String.IsNullOrWhiteSpace(project.Description))
            {
                return(CommonResult.Failure("Project description is empty."));
            }
            var existingProject = _projectsRepository.GetByName(project.Name);

            if (existingProject != null && !existingProject.IsDeleted && existingProject.Name == project.Name)
            {
                return(CommonResult.Failure("Project name already exists."));
            }

            _projectsRepository.Add(project);

            return(CommonResult.Success());
        }
Beispiel #27
0
        public CommonResult <DrinkEditDto> Edit(int?id)
        {
            var drink = _db.Drinks.Where(s => s.Id == id).FirstOrDefault();

            if (drink == null)
            {
                return(CommonResult <DrinkEditDto>
                       .Failure <DrinkEditDto>
                           ("No match id.."));
            }

            var editDrink = new DrinkEditDto
            {
                Name    = drink.Name,
                Price   = drink.Price,
                Id      = drink.Id,
                Ratings = GetRatings(id)
            };

            return(CommonResult <DrinkRating> .Success(editDrink));
        }
Beispiel #28
0
        public async Task <CommonResult <DrinkRatingDto> > SendRatingAsync(DrinkRatingDto rating)
        {
            if (rating.DrinkId == 0)
            {
                return(CommonResult <DrinkRatingDto> .Failure <DrinkRatingDto>("Drink id is 0"));
            }
            if (rating.Rating == 0)
            {
                return(CommonResult <DrinkRatingDto> .Failure <DrinkRatingDto>("Drink rating is 0 (not allowed)"));
            }

            bool RatingSuccess = await SaveChanges(rating);

            if (RatingSuccess == true)
            {
                return(CommonResult <DrinkRating> .Success(rating));
            }

            return(CommonResult <DrinkRatingDto>
                   .Failure <DrinkRatingDto>
                       ("Something unexpected happend with db"));
        }
Beispiel #29
0
        public CommonResult ValidateImageUrl(ImageValidationModel criterias)
        {
            _validationStrategyContext.SetStrategy(new ImageUrlValidationStrategy());
            if (criterias == null || string.IsNullOrEmpty(criterias.Url))
            {
                return(CommonResult.Failed(new CommonError()));
            }

            bool canUpdate = _validationStrategyContext.Validate(criterias.Url);

            if (!canUpdate)
            {
                _validationStrategyContext.SetStrategy(new Base64ImageValidationStrategy());
                canUpdate = _validationStrategyContext.Validate(criterias.Url);
            }

            if (canUpdate)
            {
                return(CommonResult.Success());
            }
            return(CommonResult.Failed(new CommonError()));
        }
Beispiel #30
0
        public async Task <ActionResult> Register([FromBody] BKRegisterInfo info)
        {
            int count = await _userReposity.CheckUserByAccountAndNickNameAsync(info.Account, info.NickName);

            if (count > 0)
            {
                // 先这样写
                return(Ok(CommonResult.Fail("account or nickName have been used")));
            }
            string salt = "baike";
            BkUser user = new BkUser {
                Account = info.Account, Password = MD5Util.GenerateMD5(info.Password, salt), Salt = salt
            };
            BkUserInfo userInfo = new BkUserInfo {
                NickName = info.NickName, State = 1, Icon = "user_default.jpg", BackgroundIcon = "back_default.jpg"
            };

            user.BkUserInfo = userInfo;
            _userReposity.AddUser(user);
            await _userReposity.SaveAsync();

            return(Ok(CommonResult.Success("register success")));
        }