예제 #1
0
        public async Task <IActionResult> Create([Bind("Title,Description,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,DeveloperUserId")] Ticket ticket, IFormFile attachment)
        {
            if (!User.IsInRole("Demo"))
            {
                if (ModelState.IsValid)
                {
                    ticket.Created     = DateTimeOffset.Now;
                    ticket.OwnerUserId = _userManager.GetUserId(User);

                    if (attachment != null)
                    {
                        AttachmentHandler attachmentHandler = new AttachmentHandler();
                        ticket.Attachments.Add(attachmentHandler.Attach(attachment));
                    }

                    _context.Add(ticket);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("MyTickets", "Tickets"));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                TempData["DemoLockout"] = "Your changes have not been saved. To make changes to the database, please log in as a full user.";
                return(RedirectToAction("MyTickets", "Tickets"));
            }
        }
        public async Task <IActionResult> Create(
            [Bind(
                 "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,DeveloperUserId")]
            Ticket ticket,
            List <IFormFile> attachments)
        {
            if (this.ModelState.IsValid)
            {
                // IF not demo user
                if (!this.User.IsInRole("DemoUser"))
                {
                    // Add file handler
                    ticket.OwnerUserId = this.userManager.GetUserId(User);
                    ticket.Created     = DateTime.Now;

                    if (attachments != null)
                    {
                        foreach (IFormFile attachment in attachments)
                        {
                            AttachmentHandler attachmentHandler = new AttachmentHandler( );
                            ticket.Attachments.Add(attachmentHandler.Attach(attachment, ticket.Id));
                        }
                    }

                    await context.AddAsync(ticket).ConfigureAwait(false);

                    await this.context.SaveChangesAsync( ).ConfigureAwait(false);

                    return(this.RedirectToAction(nameof(Index)));
                }
                else
                {
                    // Handle tempdata["DemoLockout"]
                    this.TempData["DemoLockout"] =
                        "Your changes have not been saved. You must be logged in as a full user.";

                    // Handle redirect to index
                    return(this.RedirectToAction(nameof(this.Index)));
                }
            }

            this.ViewData["DeveloperUserId"] =
                new SelectList(this.context.Users, "Id", "FullName", ticket.DeveloperUserId);
            this.ViewData["OwnerUserId"]      = new SelectList(this.context.Users, "Id", "Id", ticket.OwnerUserId);
            this.ViewData["ProjectId"]        = new SelectList(this.context.Projects, "Id", "Name", ticket.ProjectId);
            this.ViewData["TicketPriorityId"] = new SelectList(
                this.context.TicketPriorities,
                "Id",
                "Name",
                ticket.TicketPriorityId);
            this.ViewData["TicketStatusId"] = new SelectList(
                this.context.TicketStatuses,
                "Id",
                "Name",
                ticket.TicketStatusId);
            this.ViewData["TicketTypeId"] =
                new SelectList(this.context.TicketTypes, "Id", "Name", ticket.TicketTypeId);

            return(this.View(ticket));
        }