Ejemplo n.º 1
0
        // Expert image view page
        public ActionResult ExpImageView(long?id, int?page, string sortOrder, string currentFilter, string preColumn, string sucMsg)
        {
            int userID = Convert.ToInt32(Session["UserID"] != null ? Session["UserID"].ToString() : "0"); // Convert session user id to integer for comparison and prevent from NULL

            image  img = db.images.Find(id);                                                              // Find images belong to user id in DB
            report rep = (from r in db.reports
                          where r.ImgID == id
                          select r).FirstOrDefault();     // Find reports belong to this image
            comment cmt = (from s in db.comments
                           where s.ImgID == id
                           select s).FirstOrDefault();      // Find comment belong to the image

            var view = new ImgRepCmtViewModels()            // Initialise a view model for passing into view
            {
                Image   = img,
                Report  = rep,
                Comment = cmt
            };

            //string server = db.Database.Connection.DataSource.ToString(); // Get db server name for retrieving image
            //string img_link = "http://" + server + "/" + img.ImgPath;    // Concatenate image URL
            string img_link = "~/" + img.ImgPath;

            ViewBag.link       = img_link;      // Create viewbag variable for image URL
            ViewBag.Page       = page;          // Create viewbag variable for current page
            ViewBag.Order      = sortOrder;     // Create viewbag variable for current sort
            ViewBag.Filter     = currentFilter; // Create viewbag variable for current filter
            ViewBag.PreColumn  = preColumn;     // Create viewbag variable for filtering column
            ViewBag.SuccessMsg = sucMsg;        // Create viewbag variable for comment successful message
            ViewBag.userName   = (from usr in db.users
                                  where (usr.UserID == userID)
                                  select usr.UserFName).FirstOrDefault().ToString();    // Passing user first name to view
            return(View(view));
        }
Ejemplo n.º 2
0
        public ActionResult ExpImageView(ImgRepCmtViewModels IRCVmodel, int id, string submit, string page, string sortOrder, string currentFilter, string preColumn)
        {
            int    intPage = Convert.ToInt32(page); // Convert page to integer
            string message = "";                    // Intialise message

            if (IRCVmodel.Report.RepText is null)
            {
                message = "Report text cannot be emtpy";        // When report text is null
            }
            else
            {
                int    userID = Convert.ToInt32(Session["UserID"].ToString());  // Get session user id
                report repck  = (from r in db.reports
                                 where r.ImgID == id
                                 select r).FirstOrDefault(); // Check if it is first time to create report for this image

                if (repck is null)                           // When no existing report
                {
                    image  img = db.images.Find(id);         // Find the image
                    report rep = new report();               // Create a new report object
                    rep.RepText    = IRCVmodel.Report.RepText;
                    rep.RepCreator = userID;
                    rep.ImgID      = id;                                // Set report columns

                    if (submit == "save")
                    {
                        img.ImgStatus = 10;         // Change image status to report drafted
                        img.RepStatus = 2;          // Change report status to saved
                    }
                    else
                    {
                        img.ImgStatus = 2;          // Change image status to report finalised
                        img.RepStatus = 3;          // Change report status to submitted
                    }

                    if (ModelState.IsValid)
                    {
                        db.reports.Add(rep);
                        db.Entry(img).State = EntityState.Modified;
                        db.SaveChanges();
                        message = "Report created";
                    }
                }
                else                                 // When there is existing report
                {
                    image  img = db.images.Find(id); // Find the image
                    report rep = (from r in db.reports
                                  where r.ImgID == id
                                  select r).FirstOrDefault();           // Find the existing report
                    rep.RepText       = IRCVmodel.Report.RepText;
                    rep.RepCreateTime = DateTime.UtcNow;
                    rep.RepCreator    = userID;                         // Update report columns

                    if (submit == "save")                               // Check if the report is saved again
                    {
                        img.ImgStatus = 10;                             // Change image status to report drafted
                        if (ModelState.IsValid)
                        {
                            db.Entry(rep).State = EntityState.Modified;
                            db.Entry(img).State = EntityState.Modified;
                            db.SaveChanges();
                            message = "Report saved";
                        }
                    }
                    else                                                // The report is submitted
                    {
                        img.ImgStatus = 2;                              // Change image status to report finalised
                        img.RepStatus = 3;                              // Change report status to submitted
                        if (ModelState.IsValid)
                        {
                            db.Entry(rep).State = EntityState.Modified;
                            db.Entry(img).State = EntityState.Modified;
                            db.SaveChanges();
                            message = "Report submitted";
                        }
                    }
                }
            }
            return(RedirectToAction("ExpImageView", new { id, sucMsg = message, page = intPage, sortOrder = sortOrder, currentFilter = currentFilter, preColumn = preColumn }));    // Reload page
        }
Ejemplo n.º 3
0
        public ActionResult DocImageView(ImgRepCmtViewModels IRCVmodel, int id, string submit, string page, string sortOrder, string currentFilter, string preColumn)
        {
            int    intPage = Convert.ToInt32(page); // Convert page to integer
            string message = "";                    // Intialise message

            if (IRCVmodel.Comment.CmtText is null)
            {
                message = "Comment text cannot be emtpy";        // When comment text is null
            }
            else
            {
                int     userID = Convert.ToInt32(Session["UserID"].ToString()); // Get session user id
                comment cmtck  = (from c in db.comments
                                  where c.ImgID == id
                                  select c).FirstOrDefault(); // Check if it is first time to create comment for this image

                if (cmtck is null)                            // When no existing comment
                {
                    image   img = db.images.Find(id);         // Find the image
                    comment cmt = new comment();              // Create a new comment object
                    cmt.CmtText    = IRCVmodel.Comment.CmtText;
                    cmt.CmtCreator = userID;
                    cmt.ImgID      = id;                                // Set comment columns

                    if (submit == "save")
                    {
                        img.ImgStatus = 11;                  // Change image status to comment uploaded
                    }
                    else
                    {
                        img.ImgStatus = 3;                   // Change image status to closed
                        img.RepStatus = 3;                   // Change report status to submitted
                    }
                    if (ModelState.IsValid)
                    {
                        db.comments.Add(cmt);
                        db.Entry(img).State = EntityState.Modified;
                        db.SaveChanges();
                        message = "Comment created";
                    }
                }
                else                                  // When there is existing comment
                {
                    image   img = db.images.Find(id); // Find the image
                    comment cmt = (from c in db.comments
                                   where c.ImgID == id
                                   select c).FirstOrDefault();          // Find the existing comment
                    cmt.CmtText       = IRCVmodel.Comment.CmtText;
                    cmt.CmtCreateTime = DateTime.UtcNow;
                    cmt.CmtCreator    = userID;                         // Update comment columns

                    if (submit == "save")                               // Check if the comment is saved again
                    {
                        img.ImgStatus = 11;                             // Change image status to comment uploaded
                        if (ModelState.IsValid)
                        {
                            db.Entry(cmt).State = EntityState.Modified;
                            db.Entry(img).State = EntityState.Modified;
                            db.SaveChanges();
                            message = "Comment saved";
                        }
                    }
                    else                                                // The image case is closed
                    {
                        img.ImgStatus = 3;                              // Change image status to closed
                        img.RepStatus = 3;                              // Change report status to submitted
                        {
                            db.Entry(cmt).State = EntityState.Modified;
                            db.Entry(img).State = EntityState.Modified;
                            db.SaveChanges();
                            message = "Image case closed";
                        }
                    }
                }
            }
            return(RedirectToAction("DocImageView", new { id, sucMsg = message, page = intPage, sortOrder = sortOrder, currentFilter = currentFilter, preColumn = preColumn }));    // Reload page
        }