Beispiel #1
0
        public VacancyWithCommentsDto GetByVacancy(VacancyUpdateDto model)
        {
            var comments = Repository.GetWithInclude(include => include.User)
                           .Where(item => item.VacancyId == model.Id).ToArray();

            var modelWithComments = Mapper.Map <VacancyUpdateDto, VacancyWithCommentsDto>(model);

            if (comments == null || comments.Length < 1)
            {
                return(modelWithComments);
            }

            modelWithComments.CommentText      = new string[comments.Length];
            modelWithComments.CommentCreatedAt = new DateTime[comments.Length];
            modelWithComments.CommentCreatedBy = new string[comments.Length];

            for (int i = 0; i < comments.Length; i++)
            {
                modelWithComments.CommentText[i]      = comments[i].CommentText;
                modelWithComments.CommentCreatedAt[i] = comments[i].CreatedAt;
                modelWithComments.CommentCreatedBy[i] = comments[i].User.Email;
            }

            return(modelWithComments);
        }
Beispiel #2
0
        public IActionResult Edit([FromBody] VacancyUpdateDto model)
        {
            try
            {
                var updatedModel = _vacancyService.Update(model);

                var createdComment = _commentService.Create(model);

                var updateModelWithComment = _commentService.GetByVacancy(updatedModel);

                return(Ok(updateModelWithComment));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, new ErrorResponse(ex)));
            }
        }