public IActionResult Update(string id, [FromBody] VacancyUpdateModel updateRequest)
        {
            var vacancy = ControllerService.Get(id);

            if (vacancy == null)
            {
                return(new NotFoundResult());
            }

            var updatedVacancy = ControllerService.Update(id, updateRequest);

            vacancy.Update(updateRequest);
            bool success = vacancy.IsIdenticTo(updatedVacancy);

            if (!success)
            {
                return(new ConflictObjectResult(
                           new UpdatesNotMatchResponse
                {
                    Actual = updatedVacancy.ToResponse(OrganizationService),
                    Excpected = vacancy.ToResponse(OrganizationService)
                }));
            }

            return(new OkObjectResult(updatedVacancy.ToResponse(OrganizationService)));
        }
示例#2
0
        public VacancyModel Update(string id, VacancyUpdateModel updateRequest)
        {
            var vacancy = Get(id);

            if (vacancy == null)
            {
                return(null);
            }

            vacancy.Update(updateRequest);
            return(Update(id, updatedItem: vacancy));
        }
示例#3
0
        public async Task <IActionResult> EditVacancy(Guid client, VacancyUpdateModel model)
        {
            if (ModelState.IsValid)
            {
                var cmd    = new UpdateVacancyCommand(model.Id, client, model.Title, model.Description, model.OpenDate, model.CloseDate);
                var result = await _mediator.Send(cmd);

                if (result.IsFailure)
                {
                    ModelState.AddModelError("", result.Error);
                }
                else
                {
                    return(RedirectToAction(nameof(ClientController.Vacancies), new { client }));
                }
            }

            return(View(model));
        }
示例#4
0
        public IHttpActionResult UpdateVacancy([FromUri] int projectId, int vacancyId, [FromBody] VacancyUpdateModel vacancyModel)
        {
            if (Request.Headers.Authorization == null)
            {
                return(Content(HttpStatusCode.Unauthorized, "Invalid token"));
            }
            var token       = Request.Headers.Authorization.ToString();
            var tokenString = token.Substring("Basic ".Length).Trim();

            var project = _projectManager.GetProject(projectId);

            if (_authorizer.GetTokenInfo(tokenString) == null)
            {
                return(Content(HttpStatusCode.Unauthorized, "Invalid token"));
            }

            if (project.Leader != _authorizer.GetTokenInfo(tokenString).UserId)
            {
                return(Content(HttpStatusCode.Unauthorized, "Invalid token"));
            }

            if (
                _projectManager.GetProjects(prj => prj.Vacancies.Any(vaca => vaca.VacancyId == vacancyId))
                .SingleOrDefault() == null)
            {
                return(Content(HttpStatusCode.BadRequest, "Vacancy doesn't belong to this project"));
            }

            if (
                _projectManager.GetProjects(prj => prj.Vacancies.Any(vaca => vaca.VacancyId == vacancyId))
                .Single()
                .ProjectId != projectId)
            {
                return(Content(HttpStatusCode.BadRequest, "Vacancy doesn't belong to this project"));
            }

            var vacancy = _projectManager.GetVacancy(vac => vac.VacancyId == vacancyId).SingleOrDefault();

            if (vacancy == null)
            {
                return(Content(HttpStatusCode.NotFound, "Vacancy not found"));
            }

            if (vacancyModel.profession != null)
            {
                vacancy.Name = vacancyModel.profession;
            }

            if (vacancyModel.description != null)
            {
                vacancy.Description = vacancyModel.description;
            }

            if (vacancyModel.tags != null)
            {
                _projectManager.AddTagsToVacancy(vacancyModel.tags, vacancyId);
            }

            _projectManager.UpdateVacancy(vacancy);

            return(Ok(vacancyId));
        }
 public VacancyModel Update(string id, VacancyUpdateModel vacancyUpdate)
 => VacancyService.Update(id, vacancyUpdate);