public IActionResult UpdateFeedbackForm([FromBody] FeedbackFormViewModel viewModel) { bool result = this.repository.UpdateFeedbackForm(viewModel); if (result == true) { return(Ok(result)); } return(BadRequest()); }
public ActionResult SaveFeedback(FeedbackFormViewModel feedbackFormViewModel) { if (!ModelState.IsValid) { return(View("Error")); } var interview = feedbackFormViewModel.Feedback.Interview; feedbackFormViewModel.Feedback.Interview = null; feedbackFormViewModel.Feedback.SubmissionDate = DateTime.Now; _feedbacksDataAccess.CreateFeedback(feedbackFormViewModel.Feedback); var applicant = _applicantsDataAccess.GetApplicantById(interview.ApplicantId); if (interview.InterviewType == InterviewType.HR) { if (feedbackFormViewModel.Feedback.Hired) { _applicantsDataAccess.EditApplicantStatus(applicant, ApplicantStatus.HRPassed); } else { _applicantsDataAccess.EditApplicantStatus(applicant, ApplicantStatus.HRRejected); } } else if (interview.InterviewType == InterviewType.Technical) { if (feedbackFormViewModel.Feedback.Hired) { _applicantsDataAccess.EditApplicantStatus(applicant, ApplicantStatus.TechPassed); } else { _applicantsDataAccess.EditApplicantStatus(applicant, ApplicantStatus.TechRejected); } } else if (interview.InterviewType == InterviewType.HiringManager) { if (feedbackFormViewModel.Feedback.Hired) { _applicantsDataAccess.EditApplicantStatus(applicant, ApplicantStatus.HiringManagerAccepted); } else { _applicantsDataAccess.EditApplicantStatus(applicant, ApplicantStatus.HiringManagerRejected); } } return(RedirectToAction("Details", new { applicantId = interview.ApplicantId, interviewType = interview.InterviewType })); }
public bool UpdateFeedbackForm(FeedbackFormViewModel item) { if (item != null) { FeedbackForm formFromDb = this.context.FeedbackForms.Include(x => x.FeedbackQuestions).SingleOrDefault(x => x.Id == item.Id); if (formFromDb != null) { formFromDb.DeadlineDate = item.DeadlineDate; formFromDb.Name = item.Name; foreach (FeedbackQuestion questionFromDb in formFromDb.FeedbackQuestions) { // Найти в новом списке элемент с совпадающим айдишником FeedbackQuestionViewModel newQuestion = item.FeedbackQuestions.SingleOrDefault(q => q.Id == questionFromDb.Id); // если он найден, поместить в уже существующий в базе элемент новые данные if (newQuestion != null) { questionFromDb.Name = newQuestion.Name; } else // иначе удалить существующий элемент { formFromDb.FeedbackQuestions.Remove(questionFromDb); } } context.SaveChanges(); // Выбрать все вопросы, у которых айди равен -1 (то есть новые) и добавить их в список foreach (FeedbackQuestionViewModel newQuestionVM in item.FeedbackQuestions.Where(i => i.Id == -1)) { FeedbackQuestion questionToAdd = new FeedbackQuestion() { Name = newQuestionVM.Name, FeedbackForm = formFromDb, }; formFromDb.FeedbackQuestions.Add(questionToAdd); } context.SaveChanges(); } else { return(false); } } return(false); }
public ActionResult Feedback(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (_rolesManager.SetCurrentEmployee(GetCurrentUserEmail())) { if (_rolesManager.IsManager() || _rolesManager.IsStaffing()) { var formQuestions = _formQuestionsDataAccess.GetAllQuestions(FormType.FeedbackForm); var interview = _interviewsDataAccess.GetInterviewById(id); if (interview.InterviewType == InterviewType.HR && _rolesManager.IsManager()) { ViewBag.ErrorMsg = "You are not authorized to view this page"; return(View("Error")); } var feedback = new Feedback { InterviewId = (int)id, Interview = interview, FeedbackContents = new List <FeedbackContent>() }; var viewModel = new FeedbackFormViewModel { FormQuestions = formQuestions.ToList(), Feedback = feedback }; ViewBag.ProfilePic = _rolesManager.LoggedInEmployee.ProfilePic; ViewBag.Staffing = _rolesManager.IsStaffing(); return(View(viewModel)); } ViewBag.ErrorMsg = "You are not authorized to view this page"; return(View("Error")); } ViewBag.ErrorMsg = "You are not registered on our system. Plz contact the system administrator if u think this is wrong."; return(View("Error")); }
public bool AddFeedbackForm(FeedbackFormViewModel item) { if (item != null) { FeedbackForm newFeedbackForm = new FeedbackForm { DeadlineDate = item.DeadlineDate, Name = item.Name, }; foreach (FeedbackQuestionViewModel question in item.FeedbackQuestions) { FeedbackQuestion feedbackQuestion = new FeedbackQuestion { Name = question.Name, }; newFeedbackForm.FeedbackQuestions.Add(feedbackQuestion); } this.context.FeedbackForms.Add(newFeedbackForm); this.context.SaveChanges(); return(true); } return(false); }