Esempio n. 1
0
        public ActionResult Issue(ThesisAcceptModel model)
        {
            var subscription = Db.Subscriptions.OfType <OccurrenceSubscription>().SingleOrDefault(x => x.Id == model.Subscription.Id);
            var supervision  = Db.Activities.OfType <Supervision>()
                               .SingleOrDefault(x => x.Occurrence.Id == subscription.Occurrence.Id);
            var user = GetUser(subscription.UserId);

            // aus der subscription eine Thesis machen
            var subInfoService = new SemesterSubscriptionService();
            var semester       = SemesterService.GetSemester(DateTime.Today);
            var curriculum     = subInfoService.GetBestCurriculum(subscription.UserId, semester);

            int  period  = 0;
            bool success = int.TryParse(curriculum.Version, out period);

            if (!success || period == 0)
            {
                period = 3;
            }

            var student = Db.Students.FirstOrDefault(x => x.UserId.Equals(user.Id) && x.Curriculum.Id == curriculum.Id);

            if (student == null)
            {
                var curr = Db.Curricula.SingleOrDefault(x => x.Id == curriculum.Id);
                student = new Student
                {
                    UserId     = user.Id,
                    Curriculum = curr
                };

                Db.Students.Add(student);
            }


            var thesis = new Thesis();

            thesis.TitleDe        = model.Title;
            thesis.Supervision    = supervision;
            thesis.IssueDate      = DateTime.Today;
            thesis.ExpirationDate = thesis.IssueDate.Value.AddMonths(period);
            thesis.Student        = student;

            Db.Theses.Add(thesis);

            // Subscription und alle anderen löschen
            var list = Db.Activities.OfType <Supervision>().Where(x =>
                                                                  x.Occurrence.Subscriptions.Any(u => u.UserId.Equals(subscription.UserId))).ToList();

            foreach (var item in list)
            {
                var sub = item.Occurrence.Subscriptions.FirstOrDefault(x => x.UserId.Equals(user.Id));
                Db.Subscriptions.Remove(sub);
            }

            Db.SaveChanges();

            // oder zur Detailseite
            return(RedirectToAction("Thesis", "Lecturer"));
        }
Esempio n. 2
0
        public ActionResult Issue(Guid id)
        {
            var subscription = Db.Subscriptions.OfType <OccurrenceSubscription>().SingleOrDefault(x => x.Id == id);
            var supervision  = Db.Activities.OfType <Supervision>()
                               .SingleOrDefault(x => x.Occurrence.Id == subscription.Occurrence.Id);
            var user           = GetUser(subscription.UserId);
            var subInfoService = new SemesterSubscriptionService();
            var semester       = SemesterService.GetSemester(DateTime.Today);



            var model = new ThesisAcceptModel
            {
                Subscription = subscription,
                Supervision  = supervision,
                User         = user
            };

            model.Curriculum = subInfoService.GetBestCurriculum(subscription.UserId, semester);
            model.Lecturer   = supervision.Owners.First().Member;

            int period = 0;

            bool success = int.TryParse(model.Curriculum.Version, out period);

            if (!success || period == 0)
            {
                period = 3;
            }

            model.Period       = period;
            model.IssueDate    = DateTime.Today;
            model.DeliveryDate = model.IssueDate.AddMonths(period);


            return(View(model));
        }