Exemplo n.º 1
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()));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,BuildingID")] Room room)
        {
            if (id != room.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(room);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoomExists(room.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BuildingID"] = new SelectList(_context.Buildings, "ID", "ID", room.BuildingID);
            return(View(room));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Models.Program program)
        {
            if (id != program.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(program);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProgramExists(program.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(program));
        }
        public IActionResult Edit(EditCaseManagerViewModel editCMVM)
        {
            CaseManager CMtoEdit = _context.CaseManagers.Single(cm => cm.ID == editCMVM.ID);

            if (editCMVM.ID != CMtoEdit.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                CMtoEdit.FirstName   = editCMVM.FirstName;
                CMtoEdit.LastName    = editCMVM.LastName;
                CMtoEdit.PhoneNumber = editCMVM.PhoneNumber;
                CMtoEdit.Email       = editCMVM.Email;
                CMtoEdit.ProgramID   = editCMVM.ProgramID;

                _context.Update(CMtoEdit);
                _context.SaveChanges();

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

            return(View(editCMVM));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(EditBuildingViewModel editBuildingVM)
        {
            if (ModelState.IsValid)
            {
                Building BuildingtoEdit = _context.Buildings.Single(cm => cm.ID == editBuildingVM.ID);

                BuildingtoEdit.Name        = editBuildingVM.Name;
                BuildingtoEdit.Address     = editBuildingVM.Address;
                BuildingtoEdit.PhoneNumber = editBuildingVM.PhoneNumber;

                _context.Update(BuildingtoEdit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(editBuildingVM));
        }
Exemplo n.º 6
0
        public IActionResult Index()
        {
            //Check if user logged in:
            if (HttpContext.Session.GetString("Username") == null)
            {
                return(Redirect("Login"));
            }

            //Change View based on Role:
            FileMember user = _context.FileMembers.Single(u => u.Email == HttpContext.Session.GetString("Username"));

            ViewBag.Role = user.Role;

            // For Search:
            HomeViewModel homeViewModel = new HomeViewModel();

            // For Daily Tasks:
            homeViewModel.ActionFiles = _context.Files
                                        .Where(f => f.Status == Status.Damaged || f.Status == Status.Full)
                                        .Include(f => f.Consumer)
                                        .Include(f => f.CaseManager)
                                        .Include(f => f.Room)
                                        .OrderBy(f => f.Consumer.LastName);

            homeViewModel.InactiveFiles = _context.Files
                                          .Where(f => f.ShredDate <= homeViewModel.Today)
                                          .Include(f => f.Consumer)
                                          .Include(f => f.CaseManager)
                                          .Include(f => f.Room)
                                          .OrderBy(f => f.Consumer.LastName);

            foreach (File file in homeViewModel.InactiveFiles)
            {
                file.Status = Models.Status.Shred;
                _context.Update(file);
                _context.SaveChangesAsync();
            }

            return(View(homeViewModel));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(EditConsumerViewModel editConsumerVM)
        {
            if (ModelState.IsValid)
            {
                //Get consumer
                Consumer consumerToEdit = _context.Consumers.Single(c => c.ID == editConsumerVM.ID);
                // Get associated files
                consumerToEdit.Files = _context.Files.Where(f => f.ConsumerID == consumerToEdit.ID).ToList();

                consumerToEdit.LastName  = editConsumerVM.LastName;
                consumerToEdit.FirstName = editConsumerVM.FirstName;
                consumerToEdit.DOB       = editConsumerVM.DOB;

                // ONLY when a consumer's active state is changed (so it won't affect file statuses otherwise):
                if (editConsumerVM.Active != consumerToEdit.Active)
                {
                    // If consumer becomes inactive, add EndDate
                    if (editConsumerVM.Active == false)
                    {
                        consumerToEdit.Active  = false;
                        consumerToEdit.EndDate = editConsumerVM.EndDate;
                        if (consumerToEdit.Files.Count != 0)
                        {
                            // Change status of files to "Inactive" and set file ShredDate
                            foreach (File file in consumerToEdit.Files)
                            {
                                file.SetShredDate(editConsumerVM);
                                _context.Update(file);
                            }
                        }
                    }

                    // If inactive consumer becomes active, wipe EndDate and change status of files to "OK"
                    if (editConsumerVM.Active == true)
                    {
                        consumerToEdit.Active  = true;
                        consumerToEdit.EndDate = null;
                        editConsumerVM.EndDate = null;
                        if (consumerToEdit.Files.Count > 0)
                        {
                            foreach (File file in consumerToEdit.Files)
                            {
                                file.Status = Status.OK;
                                file.SetShredDate(editConsumerVM);
                                _context.Update(file);
                            }
                        }
                    }
                }

                // If the active state remains unchanged, but an inactive consumer's EndDate is changed:
                if (editConsumerVM.EndDate != consumerToEdit.EndDate)
                {
                    // NOT that we'll allow it to be wiped...
                    if (editConsumerVM.EndDate == null && editConsumerVM.Active == false)
                    {
                        consumerToEdit.EndDate = DateTime.Now;
                    }
                    else   // Otherwise, set the change to the consumer
                    {
                        consumerToEdit.EndDate = editConsumerVM.EndDate;
                    }
                    // And update their files' ShredDate
                    if (consumerToEdit.Files != null)
                    {
                        foreach (File file in consumerToEdit.Files)
                        {
                            file.SetShredDate(editConsumerVM);
                            _context.Update(file);
                        }
                    }
                }

                _context.Update(consumerToEdit);
                await _context.SaveChangesAsync();

                return(Redirect("/Consumers/Index"));
            }
            ;

            return(View(editConsumerVM));
        }