Пример #1
0
        /*==============================================================================
        * ActionResult Delete(int groupId)
        * Delete
        *
        * Default action, populates list of available scans to delete
        * ==============================================================================*/
        public ActionResult Delete(int groupId)
        {
            Entities db = new Entities();
            UserProfile user = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId);
            Group query = user.GroupsIn.Single(g => g.GroupId == groupId);

            //Populates dropdown of available scans to delete
            ScanDeleteModel model = new ScanDeleteModel()
            {
                ScanList = query.Scans,
                GroupId = groupId
            };

            return View(model);
        }
Пример #2
0
        public ActionResult Delete(ScanDeleteModel model)
        {
            if (ModelState.IsValid)
            {
                //Getting scan from user / user group
                Entities db = new Entities();
                UserProfile user = db.UserProfiles.Single(u => u.UserId == WebSecurity.CurrentUserId);
                Group group = user.GroupsIn.Single(g => g.GroupId == model.GroupId);
                Scan scan = group.Scans.Single(p => p.ScanId == model.selectedScanId);

                //Remove scan from database
                db.Scans.Remove(scan);
                db.SaveChanges();

                System.IO.File.Delete(Server.MapPath("~/Groups/" + model.GroupId + "/Scans/" + scan.GeneratedFilename));

                return RedirectToAction("Index");
            }
            else
            {
                return View(model);
            }
        }