public ActionResult Create(TicketFormViewModel viewModel)
        {
            Ticket ticket = new Ticket()
            {
                Created            = DateTime.Now,
                OwnersUser         = userHelper.GetUserFromId(User.Identity.GetUserId()),
                ProjectId          = viewModel.ProjectId,
                TicketPrioritiesId = viewModel.TicketPriorityId,
                TicketTypeId       = viewModel.TicketTypeId,
                Title       = viewModel.Title,
                Description = viewModel.Description,
            };

            int storedTicketId = ticketHelper.AddTicket(ticket);

            if (viewModel.File != null)
            {
                string attachmentPath = ticketHelper.saveFile(viewModel.File);

                TicketAttachments ticketAttachment = new TicketAttachments()
                {
                    TicketId    = storedTicketId,
                    User        = userHelper.GetUserFromId(User.Identity.GetUserId()),
                    Created     = DateTime.Now,
                    FilePath    = attachmentPath,
                    Description = viewModel.Description,
                };

                ticketHelper.AddTicketAttachment(ticketAttachment);
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Title,Description,Priority")] TicketCreateViewModel incomingTicket)
        {
            // check that the incoming model is in a valid state
            if (ModelState.IsValid)
            {
                // attempt conversion into Ticket
                Ticket       ticketToAdd  = Mapper.Map <Ticket>(incomingTicket);
                TicketHelper ticketHelper = null;
                Ticket       addedTicket  = null;

                // get the user name of the logged in user and assign as the Ticket owner
                ticketToAdd.Owner = User.Identity.Name;

                // instantiate the ticket helper
                ticketHelper = new TicketHelper(c_repository);

                // call method to add new ticket and assign created ticket to variable
                addedTicket = ticketHelper.AddTicket(ticketToAdd);

                if (addedTicket != null)
                {
                    // ticket added succesfully - insert info message into TempData so that message can be shown on tickets list view
                    this.TempData["Success"] = "Ticket created succesfully.";

                    // return user to the tickets list view
                    return(RedirectToAction("Index"));
                }
                else
                {
                    // ticket was not created because Ticket object returned by helper method was empty
                    // issue an error to the model state to reflect this
                    ModelState.AddModelError("", "Unable to create the ticket at this time. Please try again.");

                    // return view
                    return(View(incomingTicket));
                }
            }
            else
            {
                // return back to the page
                return(View(incomingTicket));
            }
        }