Example #1
0
        public async Task <IActionResult> Login([FromBody] LoginModel model)
        {
            var user = await _crudService.Find <User>(u => u.UserName == model.UserName);

            if (user == null)
            {
                user = await _crudService.Create <User>(new User()
                {
                    UserName     = model.UserName,
                    Type         = UserType.Uknown,
                    Profile      = new Profile(),
                    PasswordHash = _passwordHasher.HashPassword(model.Password)
                });

                return(Ok(GetLoginResponse(user, true)));
            }
            else
            {
                var result = _passwordHasher.VerifyHashedPassword(user.PasswordHash, model.Password);
                if (result == PasswordVerificationResult.Failed)
                {
                    return(BadRequest(ValidationResultMessages.LoginWrongCredentials));
                }
            }

            return(Ok(GetLoginResponse(user, false)));
        }
Example #2
0
        public async Task <IActionResult> UpdateOrCreate([FromBody] VacancyModel model)
        {
            var user = await _crudService.Find <User>(u => u.Id == _webSession.UserId);

            if (String.IsNullOrEmpty(user.Profile.Name))
            {
                return(BadRequest(ValidationResultMessages.CantCreateVacancyProfileEmpty));
            }

            var vacancy = await _crudService.Find <Vacancy>(v => v.UserId == _webSession.UserId && v.Id == model.Id);

            if (vacancy == null)
            {
                model.Date     = DateTime.Now;
                vacancy        = Mapper.Map <Vacancy>(model);
                vacancy.UserId = _webSession.UserId;
                vacancy        = await _crudService.Create(vacancy);

                model.Id = vacancy.Id;
            }
            else
            {
                await _crudService.Update <VacancyModel, Vacancy>(model.Id, model, (to, from) =>
                {
                    to.Description = from.Description;
                    to.Title       = from.Title;
                    to.IsClosed    = from.IsClosed;

                    to.VacancyFilter.MinExpirience = from.VacancyFilter.MinExpirience;
                    to.VacancyFilter.MinRating     = from.VacancyFilter.MinRating;

                    to.VacancyFilter.JsonMusicianRoles = from.VacancyFilter.MusicianRoles.ToJson();
                    to.VacancyFilter.JsonMusicGenres   = from.VacancyFilter.MusicGenres.ToJson();
                    to.VacancyFilter.JsonCities        = from.VacancyFilter.Cities.ToJson();
                    to.VacancyFilter.JsonWorkTypes     = from.VacancyFilter.WorkTypes.ToJson();
                });
            }

            return(Ok(model));
        }