コード例 #1
0
        /*==============================================================================
        * ActionResult Create(int groupId)
        * Create
        *
        * Default action for Create view.
        * Populates a dropdown of the available scans the user can choose for the concatinated report.
        * ==============================================================================*/
        public ActionResult Create(int groupId)
        {
            Entities db = new Entities();

            //Creates a query showing all the available scans
            //Other users scans of the same group are included
            IEnumerable<Scan> query = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId).GroupsIn.Single(g => g.GroupId == groupId).Scans;

            //Model that will be used for display
            var model = new CreateReportModel
            {
                List = query,
                groupId = groupId
            };
            return View(model);
        }
コード例 #2
0
        public ActionResult Create(CreateReportModel model)
        {
            if (ModelState.IsValid)
            {
                //Make database connection
                Entities db = new Entities();
                //Get user from database
                UserProfile user = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId);
                //Get group from the database
                Group groupIn = user.GroupsIn.Single(g => g.GroupId == model.groupId);
                //Get scans user has access to
                ICollection<Scan> ownedScans = groupIn.Scans;

                List<Scan> scans = new List<Scan>();

                //All the selected scans for creating the new report
                foreach (int scanId in model.SelectedScanIds)
                {
                    scans.Add(ownedScans.Single(s => s.ScanId == scanId));
                }

                //Creating a new blank report
                Report report = new Report()
                {
                    DateProcessed = DateTime.Now,
                    ReportName = model.ReportName
                };

                foreach (Scan s in scans)
                    report.Scans.Add(s);

                groupIn.Reports.Add(report);
                db.SaveChanges();

                return RedirectToAction("View", new { reportId = report.ReportId, groupId = report.OwnerId });
            }

            return View(model);
        }