コード例 #1
0
        public IActionResult Create(CreateCaseManagerViewModel createCMVM)
        {
            if (ModelState.IsValid)
            {
                CaseManager cm = new CaseManager()
                {
                    LastName    = createCMVM.LastName,
                    FirstName   = createCMVM.FirstName,
                    Email       = createCMVM.Email,
                    PhoneNumber = createCMVM.PhoneNumber,
                    ProgramID   = createCMVM.ProgramID
                };

                _context.Add(cm);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }

            createCMVM.Programs = _context.Programs.Select(p => new SelectListItem()
            {
                Value = p.ID.ToString(), Text = p.Name
            }).ToList();

            return(View(createCMVM));
        }
コード例 #2
0
        // GET: Files
        public async Task <IActionResult> Index()
        {
            //Check if user logged in:
            if (HttpContext.Session.GetString("Username") == null)
            {
                return(Redirect("/Home/Login"));
            }

            var fileFinderContext = _context.Files.Include(f => f.CaseManager)
                                    .Include(f => f.Consumer)
                                    .Include(f => f.Room)
                                    .OrderBy(f => f.Room.Name)
                                    .ThenBy(f => f.CaseManager.LastName)
                                    .ThenBy(f => f.Consumer.LastName)
                                    .ThenBy(f => f.Consumer.FirstName);

            //Update files that need to be shredded
            foreach (File f in fileFinderContext)
            {
                if (f.ShredDate <= DateTime.Now)
                {
                    f.Status = Status.Shred;
                    _context.Update(f);
                }
            }
            _context.SaveChanges();

            return(View(await fileFinderContext.ToListAsync()));
        }
コード例 #3
0
        public IActionResult Register(RegisterViewModel registerVM)
        {
            if (ModelState.IsValid)
            {
                //if user does not already exist:
                if (!_context.FileMembers.Any(u => u.Email == registerVM.Email))
                {
                    //if passwords match:
                    if (registerVM.Password.Equals(registerVM.Verify))
                    {
                        //make new model with VM data, hashing password
                        FileMember newUser = new FileMember
                        {
                            FirstName = registerVM.FirstName,
                            LastName  = registerVM.LastName,
                            Email     = registerVM.Email,
                            Password  = Encryption.Hash(registerVM.Password)
                        };

                        //save model to DB
                        _context.FileMembers.Add(newUser);
                        _context.SaveChanges();

                        //start session
                        HttpContext.Session.Set(SessionName, System.Text.Encoding.UTF8.GetBytes(newUser.Email));
                        string SessionNum = HttpContext.Session.GetHashCode().ToString();
                        HttpContext.Response.Cookies.Append(SessionNum, newUser.Email.ToString());

                        return(RedirectToAction(nameof(Index)));
                    }

                    ViewBag.Error = "Passwords must match.";
                    return(View(registerVM));
                }

                ViewBag.Error = "User already exists. Please login.";
                return(View(registerVM));
            }

            ViewBag.Error = "Register failed. Please try again.";
            return(View(registerVM));
        }