Esempio n. 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Username, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    AccountServiceCaller.Add(new AccountModel {
                        Email = model.Email, Password = model.Password, FullName = model.FullName, Username = model.Username, PhoneNumber = model.PhoneNumber
                    });
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
            {
                AccountModel user = AccountServiceCaller.Get(model.UserName);
                if (user != null)
                {
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    goto case SignInStatus.Failure;
                }
            }

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
        public ActionResult AddExam(ExamViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var currentUser   = AccountServiceCaller.Get(User.Identity.Name);
            var userOrganizer = OrganizerServiceCaller.Get(currentUser.OrganizerId);
            var newExam       = new ExamModel();

            newExam.OrganizerId = userOrganizer.Id;
            newExam.CourseName  = model.CourseName;
            newExam.Hour        = model.Hour;
            newExam.Date        = model.ExamDay;
            newExam.Room        = model.ExamRoom;
            newExam.Difficulty  = model.Difficulty;

            try
            {
                ExamServiceCaller.Add(newExam);
                return(RedirectToAction("Index", "Exam"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
        public ActionResult AddCourse(CourseViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var currentUser   = AccountServiceCaller.Get(User.Identity.Name);
            var userOrganizer = OrganizerServiceCaller.Get(currentUser.OrganizerId);
            var newCourse     = new CourseModel();

            newCourse.OrganizerId = userOrganizer.Id;
            newCourse.Name        = model.CourseName;
            newCourse.Hour        = model.CourseHour;
            newCourse.Professor   = model.CourseProfessor;

            newCourse.Day = GetWeekDayFromString(model.CourseDay);

            try
            {
                CourseServiceCaller.Add(newCourse);
                return(RedirectToAction("Index", "Course"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
Esempio n. 5
0
        public ActionResult ChangeUserAccountSettings(ChangeUserAccountSettingsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            AccountModel account = AccountServiceCaller.Get(User.Identity.GetUserName());

            if (!String.IsNullOrEmpty(model.Email))
            {
                account.Email = model.Email;
            }
            if (!String.IsNullOrEmpty(model.FullName))
            {
                account.FullName = model.FullName;
            }
            if (!String.IsNullOrEmpty(model.PhoneNumber))
            {
                account.PhoneNumber = model.PhoneNumber;
            }

            try
            {
                AccountServiceCaller.Update(account);
                return(RedirectToAction("Index", "Manage"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
Esempio n. 6
0
        public ActionResult Index()
        {
            var nextDay = CalculationClass.GetWeekDayFromDateTime(DateTime.Now.AddDays(1).DayOfWeek);

            ViewBag.NextDay = nextDay.ToString();
            if (Request.IsAuthenticated)
            {
                var account    = AccountServiceCaller.Get(User.Identity.Name);
                var organizer  = OrganizerServiceCaller.Get(account.OrganizerId);
                var courseList = CalculationClass.GetCoursesFromDay(organizer.Courses.ToList(), nextDay);
                ViewBag.CourseList = courseList;
                var nextExam            = CalculationClass.GetNextExam(organizer.Exams.ToList());
                var daysTillTheNextExam = 0;
                if (nextExam != null)
                {
                    daysTillTheNextExam = CalculationClass.CalculateNumberOfDaysTillActivity(nextExam.Date);
                }
                ViewBag.NextExam            = nextExam;
                ViewBag.DaysTillTheNextExam = daysTillTheNextExam;
            }
            else
            {
                ViewBag.CourseList = new List <CourseModel>();
                ViewBag.NextExam   = null;
            }
            return(View());
        }
        // GET: Exam
        public ActionResult Index()
        {
            var currentUser   = AccountServiceCaller.Get(User.Identity.Name);
            var userOrganizer = OrganizerServiceCaller.Get(currentUser.OrganizerId);
            var examList      = CalculationClass.SortExamsByDifficulty(userOrganizer.Exams.ToList());

            return(View(examList));
        }
        // GET: Course
        public ActionResult Index()
        {
            var currentUser   = AccountServiceCaller.Get(User.Identity.Name);
            var userOrganizer = OrganizerServiceCaller.Get(currentUser.OrganizerId);
            var courseList    = userOrganizer.Courses;

            courseList = CalculationClass.SortCoursesByDayAndHour(courseList.ToList());
            return(View(courseList));
        }
Esempio n. 9
0
        public ActionResult ChangeActivitySettings(ChangeSettingsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            AccountModel  account  = AccountServiceCaller.Get(User.Identity.GetUserName());
            SettingsModel settings = SettingsServiceCaller.Get(account.SettingsId);

            settings.CourseDuration = model.ActivityLenght;
            switch (model.FirstDayOfWeek)
            {
            case "Luni":
            {
                settings.StartDay = WeekDay.Luni;
                break;
            }

            case "Marti":
            {
                settings.StartDay = WeekDay.Marti;
                break;
            }

            case "Miercuri":
            {
                settings.StartDay = WeekDay.Miercuri;
                break;
            }

            case "Joi":
            {
                settings.StartDay = WeekDay.Joi;
                break;
            }

            case "Vineri":
            {
                settings.StartDay = WeekDay.Vineri;
                break;
            }
            }
            try
            {
                SettingsServiceCaller.Update(settings);
                return(RedirectToAction("Index", "Manage"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }