public IActionResult Create(CreateCommentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var ticket = _ticketFinder.Find(model.TicketId);

            ticket.AddComment(model.ToDomainObject());
            _ticketsModifier.UpdateTicket(ticket);
            return(RedirectToAction("Details", "Tickets", new { Id = model.TicketId }));
        }
예제 #2
0
        public async Task <IActionResult> UploadImage(int id, List <IFormFile> files)
        {
            if (files.Any(f => f.Length > 2097152))
            {
                ModelState.AddModelError("Images", "Maksimaalne faili suurus on 2 MB.");
                return(Details(id));
            }

            var ticket = _ticketsFinder.Find(id);

            if (ticket.AuthorId != User.GetUserId() && !User.IsInRole("Admin"))
            {
                return(Forbid());
            }

            foreach (var formFile in files)
            {
                using (var memoryStream = _memoryStreamProvider.Provide())
                {
                    await formFile.CopyToAsync(memoryStream);

                    var file = new Image(memoryStream.ToArray());
                    ticket.AddImage(file);
                }
            }

            _ticketsModifier.UpdateTicket(ticket);
            return(RedirectToAction(nameof(Index)));
        }