Example #1
0
 public HttpResponseMessage AddJob([FromBody] JobDto jobDto)
 {
     return(HandleRequestSafely(() =>
     {
         IEnumerable <string> tokenValues = new List <string>();
         Request.Headers.TryGetValues(Settings.TokenKey, out tokenValues);
         var user = _userService.GetUserByEmail(JwtManager.GetEmailFromToken(tokenValues.First()));
         if (user.UserType != UserType.Provider)
         {
             return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Only providers can create jobs");
         }
         var job = new JobFactory().GetJobFromDto(jobDto);
         job.Owner = user;
         job.Asignee = null;
         if (jobDto.Skills != null)
         {
             job.RequiredSkills = jobDto.Skills.Select(skill => _skillService.GetSkillByName(skill)).ToList();
         }
         _jobService.Add(job);
         return Request.CreateResponse(HttpStatusCode.OK);
     }));
 }
Example #2
0
 public HttpResponseMessage SaveProfile(UserProfileDto userProfileDto)
 {
     return(HandleRequestSafely(() =>
     {
         if (userProfileDto == null)
         {
             return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Body can't be empty");
         }
         IEnumerable <string> tokenValues = new List <string>();
         Request.Headers.TryGetValues(Settings.TokenKey, out tokenValues);
         var user = _userService.GetUserByEmail(JwtManager.GetEmailFromToken(tokenValues.First()));
         user.UserName = userProfileDto.Username;
         user.PhoneNumber = userProfileDto.PhoneNumber;
         if (user.UserType == DAL.Models.UserType.Client)
         {
             user.Skills = userProfileDto.Skills.Select(skill => _skillService.GetSkillByName(skill)).ToList();
         }
         _userService.Update(user);
         return Request.CreateResponse(HttpStatusCode.OK);
     }));
 }