Beispiel #1
0
        public ActionResult CreateConsultationTicket()
        {
            // convnention for making it easier to pass messages between controllers
            if (TempData["Message"] != null)
            {
                ViewBag.Message += (" " + TempData["Message"].ToString());
            }
            CreateConsultationTicket ticket = new CreateConsultationTicket();

            return(View(ticket));
        }
Beispiel #2
0
        public ActionResult CreateConsultationTicket([Bind(Include = "DescriptionName,DescriptionDetails")] CreateConsultationTicket ticket)
        {
            // convnention for making it easier to pass messages between controllers
            if (TempData["Message"] != null)
            {
                ViewBag.Message += (" " + TempData["Message"].ToString());
            }

            if (ModelState.IsValid)
            {
                OrcaContext db = new OrcaContext();

                int oid = Convert.ToInt32(Session["OrcaUserID"].ToString());

                // make sure the user hasn't already created a ticket with the same name
                if (!db.Tickets.Any(tic => (tic.OrcaUserID == oid && tic.DescriptionName == ticket.DescriptionName)))
                {
                    Ticket      newTicket      = new Ticket();
                    TicketEntry newTicketEntry = new TicketEntry();
                    DateTime    dtStamp        = DateTime.Now;

                    // enter the values for the ticket
                    newTicket.OrcaUserID      = newTicket.OrcaUserIDLastReplied = Convert.ToInt32(Session["OrcaUserID"].ToString());
                    newTicket.DTStamp         = dtStamp;
                    newTicket.DescriptionName = ticket.DescriptionName;
                    newTicket.IsTicketOpen    = true;

                    db.Tickets.Add(newTicket);
                    db.SaveChanges();

                    // enter the values for the first ticket entry
                    newTicketEntry.TicketID     = newTicket.TicketID;
                    newTicketEntry.OrcaUserID   = newTicket.OrcaUserID;
                    newTicketEntry.EntryDTStamp = dtStamp;
                    newTicketEntry.EntryText    = ticket.DescriptionDetails;

                    db.TicketEntries.Add(newTicketEntry);
                    db.SaveChanges();


                    return(RedirectToAction("EditConsultationTicket", new { newTicket.TicketID, id = newTicket.TicketID }));

                    // DOUBLE NOTE: Leaving this here for now, this was annoying and still doesn't work as I would like it, or maybe it does.
                    // NOTE: The following RedirectToAction takes me to the right url but the id value is null so I will pass it in TempData and pick it up in the EditConsultationTicket
                    // NOTE: Need to do this differently, but will have to do this workaround for now. I think the RoutConfig.cs needs to be edited in App_Start but I'm not sure.

                    //TempData["TicketID"] = newTicket.TicketID;

                    //return RedirectToAction("EditConsultationTicket", new { id = newTicket.TicketID } );
                    //("EditConsultationTicket", new RouteValueDictionary( new { Controller = "Consultee", Action = "EditConsultationTicket", Id = newTicket.TicketID }));//

                    //// the following seems to mostly work as needed, but there is something odd
                    //int id = newTicket.TicketID;
                    //return RedirectToAction("EditConsultationTicket", new { id = id , newTicket.TicketID} );
                    //// the above seems to mostly work as needed, but there is something odd
                    //int id = newTicket.TicketID;
                    //return RedirectToAction("EditConsultationTicket", new { newTicket.TicketID, id = id });
                }
                else
                {
                    ViewBag.Message += "You have previously created a ticket with the same Short Description/Name.  Please, either edit that ticket or change the Short Discription/Name of the new consultation ticket.";
                }
            }

            return(View(ticket));
        }