Пример #1
0
        public ActionResult Version(int id, CreateCommentViewModel comment)
        {
            var version = this.Data.Versions.GetById(id);
            if (this.IsThesisStudentOrTeacher(version.ThesisId))
            {
                if (ModelState.IsValid)
                {
                    var userId = this.User.Identity.GetUserId();

                    var newComment = Mapper.Map<Comment>(comment);
                    newComment.UserId = userId;
                    newComment.VersionId = id;

                    this.Data.Comments.Add(newComment);
                    this.Data.SaveChanges();

                    var logger = this.loggerCreator.Create(this.Data);
                    var log = new ThesisLog
                    {
                        ThesisId = version.ThesisId,
                        UserId = userId,
                        LogType = LogType.AddedComment,
                        ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "Version", id)
                    };
                    logger.Log(log);

                    CreateNotification(version.ThesisId, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_COMMENTED);

                    return RedirectToAction("Version", "Thesis", new { id = id });
                }

                return View(comment);
            }

            return RedirectToAction("Index", "Storage");
        }
Пример #2
0
        public ActionResult AddFinalEvaluation(int id, CreateFinalEvaluationViewModel model)
        {
            var thesis = this.Data.Theses.GetById(id);
            var userId = this.User.Identity.GetUserId();

            if (this.IsThesisTeacher(userId, thesis) && thesis.FinalEvaluation == null)
            {
                if (ModelState.IsValid)
                {
                    thesis.FinishedAt = DateTime.Now;
                    thesis.FinalEvaluation = model.FinalEvaluation;
                    this.Data.SaveChanges();

                    var logger = this.loggerCreator.Create(this.Data);
                    var log =new ThesisLog
                    {
                        ThesisId = id,
                        UserId = userId,
                        LogType = LogType.AddedFinalEvaluation,
                        ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "ThesisProfile", id)
                    };
                    logger.Log(log);

                    CreateNotification(id, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_ADDED_FINAL_EVALUATION);

                    return RedirectToAction("ThesisProfile", "Thesis", new { id = id });
                }

                return View(model);
            }

            return RedirectToAction("Index", "Storage");
        }
Пример #3
0
        public ActionResult MarkAsComplete(int id)
        {
            if (this.IsThesisStudentOrTeacher(id))
            {
                var thesis = this.Data.Theses.GetById(id);

                thesis.FinishedAt = DateTime.Now;
                thesis.IsComplete = true;
                this.Data.SaveChanges();

                var logger = this.loggerCreator.Create(this.Data);
                var userId = this.User.Identity.GetUserId();
                var log = new ThesisLog
                {
                    ThesisId = id,
                    UserId = userId,
                    LogType = LogType.CompletedThesis,
                    ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "ThesisProfile", id)
                };
                logger.Log(log);

                CreateNotification(id, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_COMPLEDED_THESIS);

                return RedirectToAction("ThesisProfile", "Thesis", new { id = id });
            }

            return RedirectToAction("Index", "Storage");
        }
Пример #4
0
        public ActionResult Create(CreateThesisViewModel model)
        {
            if (this.User.IsInRole(GlobalConstants.STUDENT))
            {
                if (ModelState.IsValid)
                {
                    var userId = this.User.Identity.GetUserId();
                    var thesis = Mapper.Map<Thesis>(model);
                    thesis.StudentId = userId;

                    this.Data.Theses.Add(thesis);

                    this.Data.SaveChanges();

                    var logger = this.loggerCreator.Create(this.Data);
                    var log = new ThesisLog
                    {
                        ThesisId = thesis.Id,
                        UserId = userId,
                        LogType = LogType.CreatedThesis,
                        ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "ThesisProfile", thesis.Id)
                    };
                    logger.Log(log);

                    CreateNotification(thesis.Id, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_INVITATION);

                    return RedirectToAction("ThesisProfile", "Thesis", new { id = thesis.Id });
                }

                var superviosors = this.Data.Teachers.All()
                                   .AsQueryable()
                                   .Project()
                                   .To<SupervisorDropDownListITemViewModel>()
                                   .ToList();

                ViewBag.SupervisorId = new SelectList(superviosors, "Id", "FullName");

                return View(model);
            }

            return RedirectToAction("Index", "Storage");
        }
Пример #5
0
        public ActionResult AddVersion(int id, CreateVersionViewModel model)
        {
            if (this.IsThesisStudentOrTeacher(id))
            {
                if (ModelState.IsValid && model.Archive != null && model.Archive.ContentLength > 0)
                {
                    var userId = this.User.Identity.GetUserId();

                    var versionId = 0;

                    try
                    {
                        versionId = SaveNewVersion(model);
                    }
                    catch (Exception)
                    {
                        return View(model);
                    }

                    UpdateParts(model.Id, model.ThesisParts);
                    UpdatePages(model.Id, model.Pages);

                    var logger = this.loggerCreator.Create(this.Data);
                    var log = new ThesisLog
                    {
                        ThesisId = model.Id,
                        UserId = userId,
                        LogType = LogType.AddedVersion,
                        ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "Version", versionId)
                    };
                    logger.Log(log);

                    CreateNotification(id, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_ADDED_VERSION);

                    return RedirectToAction("Version", "Thesis", new { id = versionId });
                }

                return View(model);
            }

            return RedirectToAction("Index", "Storage");
        }
Пример #6
0
        public ActionResult AddReview(int id, CreateReviewViewModel model)
        {
            var thesis = this.Data.Theses.GetById(id);
            var userId = this.User.Identity.GetUserId();

            if (this.IsThesisTeacher(userId, thesis) && thesis.Evaluation == null)
            {
                if (ModelState.IsValid)
                {
                    var reviewId = 0;

                    try
                    {
                        reviewId = SaveNewReview(model);
                    }
                    catch (Exception)
                    {
                        return RedirectToAction("ThesisProfile", "Thesis", new { id = id });
                    }

                    var logger = this.loggerCreator.Create(this.Data);
                    var log = new ThesisLog
                    {
                        ThesisId = id,
                        UserId = userId,
                        LogType = LogType.AddedReview,
                        ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "ThesisProfile", id)
                    };
                    logger.Log(log);

                    CreateNotification(id, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_ADDED_REVIEW);

                    return RedirectToAction("ThesisProfile", "Thesis", new { id = id });
                }
                var reviewers = this.Data.Teachers.All()
                                 .OrderBy(t => t.User.FirstName)
                                 .ThenBy(t => t.User.LastName)
                                 .AsQueryable()
                                 .Project()
                                 .To<SupervisorDropDownListITemViewModel>()
                                 .ToList();

                ViewBag.ReviewerId = new SelectList(reviewers, "Id", "FullName");

                return View(model);
            }

            return RedirectToAction("Index", "Storage");
        }
Пример #7
0
        public ActionResult AddPart(int id, IList<CreateOrUpdateThesisPartViewModel> parts)
        {
            if (this.IsThesisStudentOrTeacher(id))
            {
                if (ModelState.IsValid)
                {
                    UpdateParts(id, parts);
                    var userId = this.User.Identity.GetUserId();
                    var logger = this.loggerCreator.Create(this.Data);
                    var log = new ThesisLog
                    {
                        ThesisId = id,
                        UserId = userId,
                        LogType = LogType.AddedPart,
                        ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "ThesisProfile", id)
                    };
                    logger.Log(log);

                    CreateNotification(id, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_ADDED_PART);

                    return RedirectToAction("ThesisProfile", "Thesis", new { id = id });
                }

                return View(parts);
            }

            return RedirectToAction("Index", "Storage");
        }