Ejemplo n.º 1
0
 public IActionResult Create(string code, string name)
 {
     if (name != null && name.Length > 0 && code != null && code.Length > 0 && code.Length <= 5)
     {
         if (_context.Departments.Where(d => d.Code == code).Any())
         {
             return(RedirectToAction("Index"));
         }
         _context.Departments.Add(new Departments()
         {
             Name = name, Code = code
         });
         _context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
        /// <summary>
        /// Update the course's due date. Returns success boolean in JsonResult.
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="newDueDate"></param>
        /// <returns></returns>
        public async Task <IActionResult> UpdateCourseDueDate(int?courseId, DateTime newDueDate)
        {
            if (courseId == null || newDueDate == null)
            {
                return(new JsonResult(new { success = false }));
            }
            CourseInstance course = await _context.CourseInstance.Where(c => c.CourseInstanceId == courseId).FirstOrDefaultAsync();

            if (course == null)
            {
                new JsonResult(new { success = false });
            }
            course.DueDate = newDueDate;
            _context.SaveChanges();
            return(new JsonResult(new { success = true }));
        }
Ejemplo n.º 3
0
        public IActionResult ReadNotification(int?notificationId)
        {
            if (notificationId == null)
            {
                return(new JsonResult(new { success = false }));
            }
            Notifications notify = _context.Notifications.Include(n => n.User)
                                   .Where(n => n.NotificationId == notificationId && n.User.UserLoginEmail == User.Identity.Name).FirstOrDefault();

            if (notify == null)
            {
                return(new JsonResult(new { success = false }));
            }
            notify.Read = true;
            _context.SaveChanges();
            return(new JsonResult(new { success = true }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the course's note and the date modified.
        /// </summary>
        /// <param name="CourseInstanceId"></param>
        /// <param name="NewNote"></param>
        /// <returns></returns>
        public JsonResult ChangeNote(int CourseInstanceId, string NewNote)
        {
            CourseInstance course = _context.CourseInstance.Include(c => c.CourseNotes)
                                    .Where(c => c.CourseInstanceId == CourseInstanceId && c.Instructors.Where(ins => ins.User.UserLoginEmail == User.Identity.Name).Any())
                                    .FirstOrDefault();

            if (course == null)
            {
                return(Json(new { success = false }));
            }
            if (course.CourseNotes.Count == 0)
            {
                course.CourseNotes.Add(new CourseNotes());
            }
            course.CourseNotes.First().Note         = NewNote;
            course.CourseNotes.First().NoteModified = DateTime.Now;
            _context.SaveChanges();
            return(Json(new { success = true, noteContent = NewNote, modified = course.CourseNotes.First().NoteModified }));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                //Add user to database
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                //Add user to LOT database
                _lotContext.UserLocator.Add(new UserLocator()
                {
                    UserLoginEmail = user.UserName, UserTitle = Input.Title
                });
                _lotContext.SaveChanges();
                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }