public ActionResult Take(int id, CreateThesisViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.Identity.GetUserId();
                var thesis = Mapper.Map <Thesis>(model);
                thesis.StudentId = userId;

                this.Data.Theses.Add(thesis);

                var theme = this.Data.ThesisThemes.All()
                            .FirstOrDefault(t => t.Id == id);
                theme.IsTaken = true;

                this.Data.SaveChanges();

                var logger = this.loggerCreator.Create(this.Data);

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

                this.Data.SaveChanges();

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

            return(View(model));
        }
        public ActionResult Take(int id)
        {
            if (this.User.IsInRole(GlobalConstants.STUDENT))
            {
                var theme = this.Data.ThesisThemes.All()
                            .FirstOrDefault(t => t.Id == id);

                if (theme == null || theme.IsTaken)
                {
                    return(new HttpStatusCodeResult(400, "Bad Request"));
                }

                ViewData["SupervisorName"] = string.Format("{0} {1}", theme.Teacher.User.FirstName, theme.Teacher.User.LastName);

                var thesis = new CreateThesisViewModel
                {
                    SupervisorId = theme.TeacherId,
                    Title        = theme.Title
                };

                return(View(thesis));
            }

            return(RedirectToAction("Themes", "Idea"));
        }
        public ActionResult Create()
        {
            if (this.User.IsInRole(GlobalConstants.STUDENT))
            {
                var newThesis    = new CreateThesisViewModel();
                var superviosors = this.Data.Teachers.All()
                                   .AsQueryable()
                                   .Project()
                                   .To <SupervisorDropDownListITemViewModel>()
                                   .ToList();

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

                return(View(newThesis));
            }

            return(RedirectToAction("Index", "Storage"));
        }
        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"));
        }
        public ActionResult Take(int id, CreateThesisViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.Identity.GetUserId();
                var thesis = Mapper.Map<Thesis>(model);
                thesis.StudentId = userId;

                this.Data.Theses.Add(thesis);

                var theme = this.Data.ThesisThemes.All()
                      .FirstOrDefault(t => t.Id == id);
                theme.IsTaken = true;

                this.Data.SaveChanges();

                var logger = this.loggerCreator.Create(this.Data);

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

                this.Data.SaveChanges();

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

            return View(model);
        }
        public ActionResult Take(int id)
        {
            if (this.User.IsInRole(GlobalConstants.STUDENT))
            {
            var theme = this.Data.ThesisThemes.All()
                     .FirstOrDefault(t => t.Id == id);

            if (theme == null || theme.IsTaken)
            {
                return new HttpStatusCodeResult(400, "Bad Request");
            }

            ViewData["SupervisorName"] = string.Format("{0} {1}", theme.Teacher.User.FirstName, theme.Teacher.User.LastName);

            var thesis = new CreateThesisViewModel
            {
                SupervisorId = theme.TeacherId,
                Title = theme.Title
            };

            return View(thesis);
            }

            return RedirectToAction("Themes", "Idea");
        }
        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");
        }
        public ActionResult Create()
        {
            if (this.User.IsInRole(GlobalConstants.STUDENT))
            {
                var newThesis = new CreateThesisViewModel();
                var superviosors = this.Data.Teachers.All()
                                      .AsQueryable()
                                      .Project()
                                      .To<SupervisorDropDownListITemViewModel>()
                                      .ToList();

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

                return View(newThesis);
            }

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