コード例 #1
0
        public ActionResult Create()
        {
            var ticket = new TicketCreateUpdateViewModel
            {
                MedaData = new TicketsMetaDataViewModel
                {
                    CategoriesList = this.GetCategoriesList(),
                    StatusesList = this.GetStatusesList(),
                    PrioritiesList = this.GetPrioritiesList()
                }
            };

            return this.View(ticket);
        }
コード例 #2
0
        public ActionResult Create(TicketCreateUpdateViewModel ticketViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                ticketViewModel.MedaData = new TicketsMetaDataViewModel
                {
                    CategoriesList = this.GetCategoriesList(),
                    StatusesList = this.GetStatusesList(),
                    PrioritiesList = this.GetPrioritiesList()
                };

                return this.View(ticketViewModel);
            }

            var userId = this.User.Identity.GetUserId();
            var user = this.Data.Users.GetById(userId);

            user.Points++;

            var ticket = new Ticket()
            {
                AuthorId = userId,
                CategoryId = ticketViewModel.CategoryId,
                Description = ticketViewModel.Description,
                Priority = ticketViewModel.Priority,
                Title = ticketViewModel.Title,
            };

            this.Data.Tickets.Add(ticket);
            this.Data.SaveChanges();

            this.AddAttachments(ticket);

            this.Data.Tickets.Update(ticket);
            this.Data.SaveChanges();

            return this.RedirectToAction("Index");
        }
コード例 #3
0
        public ActionResult Edit(int? id, TicketCreateUpdateViewModel ticketViewModel)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var ticketId = id.GetValueOrDefault();
            var ticket = this.Data.Tickets.GetById(ticketId);

            if (ticket == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            if (!this.ModelState.IsValid)
            {
                ticketViewModel.MedaData = new TicketsMetaDataViewModel
                {
                    CategoriesList = this.GetCategoriesList(),
                    StatusesList = this.GetStatusesList(),
                    PrioritiesList = this.GetPrioritiesList()
                };

                return this.View(ticketViewModel);
            }

            ticket.CategoryId = ticketViewModel.CategoryId;
            ticket.Description = ticketViewModel.Description;
            ticket.Priority = ticketViewModel.Priority;
            ticket.Title = ticketViewModel.Title;
            ticket.Status = ticketViewModel.Status;

            this.AddAttachments(ticket);

            this.Data.Tickets.Update(ticket);
            this.Data.SaveChanges();

            return this.RedirectToAction("Details", new { Id = ticket.Id });
        }
コード例 #4
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var ticketId = id.GetValueOrDefault();
            var ticket = this.Data.Tickets.GetById(ticketId);

            if (ticket == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            var ticketViewModel = new TicketCreateUpdateViewModel()
            {
                CategoryId = ticket.CategoryId,
                Description = ticket.Description,
                Priority = ticket.Priority,
                Status = ticket.Status,
                Title = ticket.Title,
                Id = ticket.Id,
                MedaData = new TicketsMetaDataViewModel
                {
                    CategoriesList = this.GetCategoriesList(),
                    StatusesList = this.GetStatusesList(),
                    PrioritiesList = this.GetPrioritiesList()
                }
            };

            return this.View(ticketViewModel);
        }