Ejemplo n.º 1
0
        public IList <FTSDTOForTeacher> ConvertToFTSDtoListForTeacher(List <FormToTeacherSubject> fTSs)
        {
            IList <FTSDTOForTeacher> dtos = new List <FTSDTOForTeacher>();

            foreach (var fts in fTSs)
            {
                FTSDTOForTeacher dto = ConvertToFTSDTOForTeacher(fts);
                dtos.Add(dto);
            }

            return(dtos);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetFormsToTeachersSubjectsById(int id)
        {
            string userId   = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
            string userRole = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == ClaimTypes.Role).Value;

            logger.Info("UserRole: " + userRole + ", UserId: " + userId + ": Requesting FormToTeacherSubject by id: " + id);

            try
            {
                FormToTeacherSubject formToTeacherSubject = formsToTeacherSubjectsService.GetByID(id);

                if (formToTeacherSubject == null)
                {
                    logger.Info("The formToTeacherSubject with id: " + id + " was not found.");
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "The formToTeacherSubject with id: " + id + " was not found."));
                }
                if (userRole == "admin")
                {
                    logger.Info("Requesting found FormToTeacherSubject convert for " + userRole + "role.");
                    FTSDTOForAdmin dto = toDTO.ConvertToFTSDTOForAdmin(formToTeacherSubject);
                    if (dto == null)
                    {
                        logger.Info("Failed!");
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Something went wrong."));
                    }
                    logger.Info("Success!");
                    return(Request.CreateResponse(HttpStatusCode.OK, dto));
                }
                else //if (userRole == "teacher")
                {
                    logger.Info("Requesting found FormToTeacherSubject convert for " + userRole + "role.");
                    FTSDTOForTeacher dto = toDTO.ConvertToFTSDTOForTeacher(formToTeacherSubject);
                    if (dto == null)
                    {
                        logger.Info("Failed!");
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Something went wrong."));
                    }
                    logger.Info("Success!");
                    return(Request.CreateResponse(HttpStatusCode.OK, dto));
                }
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }