public async Task <IActionResult> UpdateMainInfo([FromBody] MainProfileModel model)
        {
            await _crudService.Update <MainProfileModel, Profile>(_webSession.UserId, model, (to, from) =>
            {
                to.IsActivated       = from.IsActivated;
                to.Name              = from.Name;
                to.GroupName         = from.GroupName;
                to.Age               = from.Age;
                to.Experience        = from.Experience;
                to.Description       = from.Description;
                to.PhotoBase64       = from.PhotoBase64;
                to.JsonWorkTypes     = from.WorkTypes.ToJson();
                to.JsonMusicianRoles = from.MusicianRoles.ToJson();
                to.JsonMusicGenres   = from.MusicGenres.ToJson();

                if (to.User.Type == UserType.Musician)
                {
                    var vacancy         = to.User.Vacancies.FirstOrDefault();
                    vacancy.Title       = from.Name;
                    vacancy.Description = from.Description;
                    vacancy.IsClosed    = !from.IsActivated;
                    vacancy.VacancyFilter.JsonMusicianRoles = from.MusicianRoles.ToJson();
                    vacancy.VacancyFilter.JsonMusicGenres   = from.MusicGenres.ToJson();
                }
            });

            return(Ok());
        }
Beispiel #2
0
        public async Task <IActionResult> SelectUserType([FromBody] SelectUserTypeModel model)
        {
            var user = await _crudService.Find <User>(u => u.Id == _webSession.UserId);

            if (user.Type != UserType.Uknown)
            {
                return(BadRequest());
            }

            user = await _crudService.Update <SelectUserTypeModel, User>(_webSession.UserId, model, (to, from) =>
            {
                to.Type = from.UserType;
                if (to.Type == UserType.Musician)
                {
                    to.Vacancies.Add(new Vacancy()
                    {
                        Date          = DateTime.Now,
                        VacancyFilter = new VacancyFilter(),
                        IsClosed      = true
                    });
                }
            });

            return(Ok(GetLoginResponse(user, false)));
        }
Beispiel #3
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));
        }