public ActionResult <MentorRequest> DenyMentor([FromBody] MentorRequestParams requestParams)
        {
            if (!MentorRequestValidator.IsExistsRequest(requestParams))
            {
                return(BadRequest(ErrorHandler.GenerateError(ErrorHandler.MentorRequestDoesNotExists)));
            }

            return(_mentorRequestRepo.ChangeState(requestParams, RequestState.Denied));
        }
Esempio n. 2
0
        public bool AddMentorOnProject(MentorRequestParams requestParams)
        {
            var project = _context.Project.Find(requestParams.ProjectID);

            project.FK_Mentor = requestParams.MentorID;
            _context.SaveChanges();

            return(true);
        }
        public MentorRequest ChangeState(MentorRequestParams requestParams, int requestState)
        {
            var mr = Find(requestParams);

            mr.State = requestState;

            _context.SaveChanges();

            return(mr);
        }
        public ActionResult <MentorRequest> AcceptMentor([FromBody] MentorRequestParams requestParams)
        {
            if (!MentorRequestValidator.IsExistsRequest(requestParams))
            {
                return(BadRequest(ErrorHandler.GenerateError(ErrorHandler.MentorRequestDoesNotExists)));
            }

            _projectRepo.AddMentorOnProject(requestParams);
            return(_mentorRequestRepo.ChangeState(requestParams, RequestState.Accepted));
        }
        public MentorRequest CreateRequest(MentorRequestParams requestParams)
        {
            var mentorRequest = new MentorRequest
            {
                FK_Mentor   = requestParams.MentorID,
                FK_Project  = requestParams.ProjectID,
                CreatedTime = DateTime.Now,
                State       = RequestState.Created
            };

            _context.MentorRequest.Add(mentorRequest);
            _context.SaveChanges();

            return(mentorRequest);
        }
        public ActionResult <MentorRequest> CreateRequest([FromBody] MentorRequestParams requestParams)
        {
            if (!MentorValidator.IsMentorExists(requestParams.MentorID))
            {
                return(BadRequest(ErrorHandler.GenerateError(ErrorHandler.MentorNotFound)));
            }

            if (!ProjectValidator.IsProjectExists(requestParams.ProjectID))
            {
                return(BadRequest(ErrorHandler.GenerateError(ErrorHandler.ProjectNotFound)));
            }

            if (MentorRequestValidator.IsExistsRequest(requestParams))
            {
                return(BadRequest(ErrorHandler.GenerateError(ErrorHandler.MentorRequestExists)));
            }

            return(_mentorRequestRepo.CreateRequest(requestParams));
        }
 public MentorRequest Find(MentorRequestParams requestParams)
 {
     return(_context.MentorRequest
            .Where(r => r.FK_Project == requestParams.ProjectID && r.FK_Mentor == requestParams.MentorID)
            .FirstOrDefault());
 }
 public static bool IsExistsRequest(MentorRequestParams requestParams)
 {
     return(_context.MentorRequest.Where(r => r.FK_Mentor == requestParams.MentorID && r.FK_Project == requestParams.ProjectID)
            .Any());
 }