Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,ProjectId,TicketTypeId,TicketPriorityId,Title,Description")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                ticket.SubmitterId    = User.Identity.GetUserId();
                ticket.TicketStatusId = db.TicketStatus.FirstOrDefault(t => t.Name == "New").Id;
                ticket.Created        = DateTime.Now;
                db.Tickets.Add(ticket);
                db.SaveChanges();
                return(RedirectToAction("Dashboard", "Home"));
            }
            // I need to somehow produce a list of only my Projects and then put that list into the SelectList
            var myUserId   = User.Identity.GetUserId();
            var myProjects = projHelper.ListUserProjects(myUserId);

            if (ticket.ProjectId == 0)
            {
                ViewBag.ProjectId = new SelectList(myProjects, "Id", "Name");
            }

            ViewBag.DeveloperId      = new SelectList(ticketHelper.AssignableDevelopers(ticket.ProjectId), "Id", "FullName", ticket.DeveloperId);
            ViewBag.SubmitterId      = new SelectList(db.Users, "Id", "FirstName");
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name");
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatus, "Id", "Name");
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name");

            return(View(ticket));
        }
Exemplo n.º 2
0
        //Custom Action Filter that detects whether or they should be here
        //[SpecialTicketAuth]
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            var bMyTicket = ticketHelper.IsMyTicket(ticket.Id);

            if (bMyTicket)
            {
                var projName    = ticketHelper.TicketProjectName(ticket.Id);
                var DeveloperId = ticketHelper.AssignableDevelopers(ticket.ProjectId);
                ViewBag.CardTitle = "";
                ViewBag.CardTitle = projName + ": " + ticket.Title;

                ViewBag.DeveloperId      = new SelectList(DeveloperId, "Id", "FullName", ticket.DeveloperId);
                ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
                ViewBag.TicketStatusId   = new SelectList(db.TicketStatus, "Id", "Name", ticket.TicketStatusId);
                ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
                return(View(ticket));
            }
            else
            {
                TempData["InvalidSelection"] = $"You are not authorized to edit this ticket.";
                return(RedirectToAction("Dashboard", "Home"));
            }
        }