예제 #1
0
        //Adding Issue
        //GET
        public ActionResult Add()
        {
            var obj = new Issues();
            Sites s = new Sites();
            s.SitesList = new SelectList(s.GetAllSites(), "SiteID", "SiteName");
            obj.Sites = s;

            return View(obj);
        }
예제 #2
0
        public ActionResult Update(Issues issue)
        {
            String thisPageUrl = this.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
            TempData["previous"] = thisPageUrl;

            if (ModelState.IsValid)
            {
                try
                {
                    if (issue != null)
                    {
                        try
                        {
                            issue.LastUpdatedBy = LoggedUser();
                            issue.LastUpdatedDate = DateTime.Now;
                            db.Entry(issue).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            TempData["previous"] = "Search";
                            TempData["message"] = "The issue was updated.";
                            return View("~/Views/Shared/Success.cshtml");
                        }
                        catch (Exception e)
                        {
                            TempData["message"] = "There was an error. Try again or contact administrator.";
                            return View("~/Views/Shared/Error.cshtml");
                        }
                    }
                    else
                    {
                        TempData["message"] = "There was an error. Try again or contact administrator.";
                        return View("~/Views/Shared/Error.cshtml");
                    }
                }
                catch (Exception e)
                {
                    TempData["message"] = "There was an error. Try again or contact administrator.";
                    return View("~/Views/Shared/Error.cshtml");
                }
            }

            Sites site = new Sites();
            var sites = from s in db.Sites where s.SiteID == issue.SiteID select s;
            if (sites.Count() > 0) { site = sites.First(); }
            site.SitesList = new SelectList(site.GetAllSites(), "SiteID", "SiteName");
            issue.Sites = site;
            return View(issue);
        }
예제 #3
0
        public ActionResult Search(string SelectedSite)
        {
            Sites site = new Sites();
            if (!string.IsNullOrEmpty(SelectedSite))
            {
                int SiteID = int.Parse(SelectedSite);
                site = db.Sites.Find(SiteID);
                if (site != null)
                {
                    //issues
                    var issues = from i in db.Issues where i.SiteID == SiteID select i;
                    Issues issue = new Issues();
                    site.SitesList = new SelectList(site.GetAllSites(), "SiteID", "SiteName");
                    issue.Sites = site;
                    issue.SiteIssues = issues.ToList();
                    ViewBag.Error = false;
                    return View(issue);
                }
                else
                {
                    ViewBag.Message = "There are not issues for the selected site.";
                    return View();
                }
            }

            ViewBag.Error = true;
            ModelState.AddModelError("Site", "You must select a site.");
            var obj = new Issues();
            site = new Sites();
            site.SitesList = new SelectList(site.GetAllSites(), "SiteID", "SiteName");
            obj.Sites = site;
            return View(obj);
        }
예제 #4
0
        public ActionResult Add(Issues issue)
        {
            String thisPageUrl = this.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
            TempData["previous"] = thisPageUrl;

            if (!string.IsNullOrEmpty(issue.SelectedSite))
            {

                try
                {
                    //getting site
                    int id = int.Parse(issue.SelectedSite);
                    Sites site = db.Sites.Find(id);

                    if (site != null)
                    {
                        //registration data
                        issue.RegisteredBy = LoggedUser();
                        issue.RegisteredDate = DateTime.Now;
                        issue.SiteID = id;

                        if (ModelState.IsValid)
                        {
                            if (issue.EndDate != null)
                            {
                                if (issue.EndDate < issue.StartDate)
                                {
                                    ModelState.AddModelError("EndDate", "End date should be greater than start date");
                                    var obj = new Issues();
                                    Sites s = new Sites();
                                    s.SitesList = new SelectList(s.GetAllSites(), "SiteID", "SiteName");
                                    obj.Sites = s;

                                    return View(obj);
                                }
                                else
                                {
                                    try
                                    {
                                        //adding to database
                                        db.Issues.Add(issue);
                                        db.SaveChanges();

                                        //redirecting
                                        TempData["message"] = "The issue was saved.";
                                        return View("~/Views/Shared/Success.cshtml");
                                    }
                                    catch (Exception e)
                                    {
                                        TempData["message"] = "There was an error saving issue.  Try again or contact administrator.";
                                        return View("~/Views/Shared/Error.cshtml");
                                    }
                                }
                            }
                            else
                            {
                                try
                                {
                                    //adding to database
                                    db.Issues.Add(issue);
                                    db.SaveChanges();

                                    //redirecting
                                    TempData["message"] = "The issue was saved.";
                                    return View("~/Views/Shared/Success.cshtml");
                                }
                                catch (Exception e)
                                {
                                    TempData["message"] = "There was an error saving issue.  Try again or contact administrator.";
                                    return View("~/Views/Shared/Error.cshtml");
                                }
                            }

                        }
                        else
                        {
                            var obj = new Issues();
                            Sites s = new Sites();
                            s.SitesList = new SelectList(s.GetAllSites(), "SiteID", "SiteName");
                            obj.Sites = s;

                            return View(obj);
                        }
                    }
                    else
                    {
                        TempData["message"] = "The site doesn't exist.  Try again or contact administrator.";
                        return View("~/Views/Shared/Error.cshtml");
                    }
                }
                catch (Exception e)
                {
                    TempData["message"] = "There was an error saving issue.  Try again or contact administrator.";
                    return View("~/Views/Shared/Error.cshtml");
                }

            }
            else
            {
                ModelState.AddModelError("Site", "You must select a site.");
                var obj = new Issues();
                Sites s = new Sites();
                s.SitesList = new SelectList(s.GetAllSites(), "SiteID", "SiteName");
                obj.Sites = s;

                return View(obj);
            }
        }
예제 #5
0
 //List All Issue
 public ActionResult AllIssues()
 {
     Issues issue = new Issues();
     var issues = issue.GetAllIssues();
     if (issues.Count() > 0)
     {
         return View(issues.ToList());
     }
     else
     {
         ViewBag.Message = "There are not registered issues.";
         return View();
     }
 }