public ActionResult Upload(int? id, HttpPostedFileBase file)
        {
            if (id == null || file == null || CurrentUser.ProjectId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Ticket ticket = db.Tickets.Where(m => m.Id == id && m.ProjectId == CurrentUser.ProjectId).First();

            if (file.ContentLength > 0)
            {
                TicketAttachment attachment = new TicketAttachment();
                attachment.UploadDate = DateTimeOffset.UtcNow;
                attachment.TicketId = ticket.Id;
                attachment.UploaderId = (int)CurrentUser.UserId;
                attachment.FileName = Path.GetFileName(file.FileName);
                attachment.MemeType = file.ContentType;

                var md5 = MD5.Create();
                attachment.FileHash = string.Join("", md5.ComputeHash(file.InputStream).Select(x => x.ToString("x2")));

                var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), attachment.FileHash);

                file.SaveAs(path);

                db.Entry(attachment).State = EntityState.Added;
                UpdateTicket(ticket, "File Attached");
            }

            return RedirectToAction("Details", "Ticket", new { id = (int)id });
        }
Ejemplo n.º 2
0
        // GET: TicketAttachments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            return(View(ticketAttachment));
        }
        // GET: TicketAttachments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Oops5", "Home", null));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(RedirectToAction("Oops5", "Home", null));
            }
            return(View(ticketAttachment));
        }
Ejemplo n.º 4
0
        public static void AnyAttachment(Ticket ticket, TicketAttachment attachment, bool add)
        {
            var newHistory = new TicketHistory
            {
                UserId       = HttpContext.Current.User.Identity.GetUserId(),
                Updated      = DateTime.Now,
                PropertyName = "Ticket Attachment",
                OldValue     = add? "": attachment.Title,
                NewValue     = add? attachment.Title : "",
            };

            ticket.TicketHistories.Add(newHistory);
            db.TicketHistories.Add(newHistory);
        }
Ejemplo n.º 5
0
        public ActionResult CreateAttachment([Bind(Include = "Id,TicketId,FileUrl,Created,Description,AuthorId")] TicketAttachment ticketattachment, HttpPostedFileBase image)
        { // only pass in the bind the attributes that have forms
            var userId   = User.Identity.GetUserId();
            var userName = db.Users.Find(User.Identity.GetUserId()).FullName;
            var user     = db.Users.Find(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                if (image != null && image.ContentLength > 0)
                {
                    var ext = Path.GetExtension(image.FileName).ToLower();
                    if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" && ext != ".bmp" && ext != ".pdf" && ext != ".doc" && ext != ".docx" && ext != ".html")
                    {
                        ModelState.AddModelError("image", "Invaild Format.");
                    }
                }
                if (!String.IsNullOrWhiteSpace(ticketattachment.Description))
                {
                    var ticket = db.Tickets.Find(ticketattachment.TicketId);

                    if (image != null)
                    {
                        var filepath = "/Assets/img/";
                        var absPath  = Server.MapPath("~" + filepath);

                        if (ticketattachment.FileUrl != string.Empty)
                        {
                            ticketattachment.FileUrl = filepath + image.FileName;
                            image.SaveAs(Path.Combine(absPath, image.FileName));
                        }
                    }
                    ticketattachment.Created  = System.DateTime.Now;
                    ticketattachment.AuthorId = User.Identity.GetUserId();
                    db.TicketAttachments.Add(ticketattachment);
                    db.SaveChanges();

                    Notification newNotification = new Notification();
                    newNotification.TicketId = ticket.Id;
                    newNotification.Message  = "An attachment has been added by " + userName;
                    newNotification.Created  = DateTimeOffset.Now;
                    newNotification.UserId   = ticket.AssignToUserId; // string type because it is a hash code rather than a regular int Id
                    db.Notifications.Add(newNotification);
                    db.SaveChanges();

                    return(RedirectToAction("Details", new { id = ticket.Id }));
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Download(int?id)
        {
            // check your inputs
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var Attach   = db.TicketAttachments.Find(id);
            var contType = TicketAttachment.GetMimeType(Attach.OriginalName);
            var file     = File(Attach.AttachmentFilePath, contType, Attach.OriginalName);

            return(file);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,TicketId,FilePath,Description,Created,FileUrl,UserId")] TicketAttachment ticketAttachment, Ticket tick, Ticket oldTicket)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ticketAttachment).State = EntityState.Modified;
                db.SaveChanges();
                await Notify.TriggerNotifications(tick, oldTicket);

                return(RedirectToAction("Index"));
            }
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
Ejemplo n.º 8
0
        // GET: TicketAttachments/Create
        public ActionResult Create(int id)
        {
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title");

            TicketAttachment ticketAttachment = new TicketAttachment();

            ticketAttachment.TicketId = id;
            ticketAttachment.Ticket   = db.Tickets.FirstOrDefault(t => t.Id == id);
            var currentUser = User.Identity.GetUserId();

            ticketAttachment.UserId = currentUser;
            ticketAttachment.User   = db.Users.FirstOrDefault(u => u.Id == currentUser);
            return(View(ticketAttachment));
        }
Ejemplo n.º 9
0
 public ActionResult EditAttchment(int id, TicketAttachment attchment)
 {
     if (ModelState.IsValid)
     {
         var oldA = db.Attachments.Find(id);
         attchment.TicketId = oldA.TicketId;
         attchment.Date     = DateTime.Now;
         attchment.UserId   = User.Identity.GetUserId();
         TicketHelper.DeleteAttchmentFormTcket(id);
         TicketHelper.AddAttchmentToTcket(db, attchment);
         return(RedirectToAction("Detail", "Tickets", new { id = attchment.TicketId }));
     }
     return(View("AddAttchmentToTicket", attchment));
 }
Ejemplo n.º 10
0
        public virtual JsonResult AddAttachment(int?id)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase userPostedFile = Request.Files[0];
                    {
                        var attachment = new TicketAttachment();

                        string fName = Path.GetFileName(userPostedFile.FileName);

                        attachment.FileName = fName;

                        attachment.FileSize = userPostedFile.ContentLength;
                        string mtype = userPostedFile.ContentType;
                        attachment.FileType = (string.IsNullOrEmpty(mtype) ? "application/octet-stream" : mtype);
                        byte[] fileContent = new byte[userPostedFile.ContentLength];
                        userPostedFile.InputStream.Read(fileContent, 0, userPostedFile.ContentLength);

                        var isDemo = (bool)Settings.ApplicationSettings.GetSettingValue("IsDemo");

                        if (isDemo)
                        {
                            attachment.FileContents = System.Text.Encoding.UTF8.GetBytes("The demo does not store upload content...");
                        }
                        else
                        {
                            attachment.FileContents = fileContent;
                        }
                        try
                        {
                            System.Threading.Thread.Sleep(2000);
                            int fileId = Tickets.AddPendingAttachment(id, attachment);
                            return(new JsonResult()
                            {
                                ContentType = "text/plain", Data = new { success = true, id = fileId.ToString() }
                            });
                        }
                        catch
                        {
                            return(new JsonResult());
                        }
                    }
                }
                throw new InvalidOperationException("No file data was uploaded");
            }
            throw new InvalidOperationException("The user is not authenticated.");
        }
Ejemplo n.º 11
0
        public void updateTicketAttachment(TicketAttachmentViewModel ticketAttachmentViewModel)
        {
            TicketAttachment ticketAttachment = TicketAttachmentRepo.GetEntity(x => x.Id == ticketAttachmentViewModel.Id);

            Ticket ticket   = TicketRepo.GetEntity(x => x.Id == ticketAttachment.TicketId);
            var    stream   = ticketAttachmentViewModel.FileData.InputStream;
            var    fileName = ticketAttachmentViewModel.FileData.FileName;

            File.Delete(ticketAttachment.FilePath);

            string source  = Path.GetDirectoryName(ticketAttachment.FilePath) + "\\" + fileName;
            int    n       = ticketAttachment.FileURL.LastIndexOf("/");
            string fileURL = ticketAttachment.FileURL.Substring(0, n) + "/" + fileName;

            FileInfo fi = new FileInfo(source);
            var      di = fi.Directory;

            di.Create();

            ticketAttachment.FilePath    = source;
            ticketAttachment.Description = ticketAttachmentViewModel.Description;
            ticketAttachment.Created     = DateTime.Now;
            ticketAttachment.FileURL     = fileURL;
            TicketAttachmentRepo.Update(ticketAttachment);

            using (stream)
            {
                using (FileStream fsWrite = new FileStream(source, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    byte[] buffer = new byte[1024 * 1024 * 5];

                    while (true)
                    {
                        int r = stream.Read(buffer, 0, buffer.Length);
                        if (r == 0)
                        {
                            break;
                        }
                        fsWrite.Write(buffer, 0, r);
                    }
                }
            }

            if (ticket.AssignedToUserId != null)
            {
                TicketNotification notification = new TicketNotification(ticket.AssignedToUserId, ticket.Id, true);
                TicketNotificationRepo.Add(notification);
            }
        }
Ejemplo n.º 12
0
        //[Authorize(Roles = "Submitter")]
        public ActionResult CreateAttachment(int ticketId, [Bind(Include = "Id,Description,TicketTypeId")] TicketAttachment ticketAttachment, HttpPostedFileBase image)
        {
            var tickets = db.Tickets
                          .Where(p => p.Id == ticketId)
                          .FirstOrDefault();
            var userId = User.Identity.GetUserId();
            var ProjectMangerOrDeveloperId = db.Users.Where(p => p.Id == userId).FirstOrDefault();
            var projectsIds = ProjectMangerOrDeveloperId.Projects.Select(p => p.Id).ToList();
            var projects    = db.Tickets.Where(p => projectsIds.Contains(p.ProjectId)).ToList();

            if (ModelState.IsValid)
            {
                if (image == null)
                {
                    return(HttpNotFound());
                }

                if (!ImageUploadValidator.IsWebFriendlyImage(image))
                {
                    ViewBag.ErrorMessage = "Please upload an image";
                }
                if ((User.IsInRole("Admin")) || (User.IsInRole("Project Manager") && projects.Any(p => p.Id == ticketId)) || (User.IsInRole("Submitter") && tickets.CreaterId == userId) || (User.IsInRole("Developer") && tickets.Assignee.Id == userId))
                {
                    var fileName = Path.GetFileName(image.FileName);
                    image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                    ticketAttachment.FilePath = "/Uploads/" + fileName;
                    ticketAttachment.UserId   = User.Identity.GetUserId();
                    ticketAttachment.Created  = DateTime.Now;
                    ticketAttachment.TicketId = ticketId;
                    db.TicketAttachments.Add(ticketAttachment);
                    var user = db.Users.FirstOrDefault(p => p.Id == ticketAttachment.UserId);
                    var personalEmailService = new PersonalEmailService();
                    var mailMessage          = new MailMessage(
                        WebConfigurationManager.AppSettings["emailto"], user.Email);
                    mailMessage.Body       = "DB Has a new attachment";
                    mailMessage.Subject    = "New Attachment";
                    mailMessage.IsBodyHtml = true;
                    personalEmailService.Send(mailMessage);
                    db.SaveChanges();
                }
                else if (User.Identity.IsAuthenticated)
                {
                    ViewBag.ErrorMessage = "Sorry! you are not allowed to attach document.";
                    return(View("Details", tickets));
                }
                return(RedirectToAction("Details", new { id = ticketId }));
            }
            return(View(ticketAttachment));
        }
        // GET: TicketAttachments/Delete/5
        public ActionResult Delete(int?id, string originAction)
        {
            TempData["originAction"] = originAction;
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            return(View(ticketAttachment));
        }
Ejemplo n.º 14
0
        // GET: TicketAttachments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            return(View(ticketAttachment));
        }
Ejemplo n.º 15
0
        private void TicketAttachmentDelete(TicketAttachment oldAttachment)
        {
            var history = new AttachmentHistory()
            {
                TicketId  = oldAttachment.TicketId,
                UserId    = HttpContext.Current.User.Identity.GetUserId(),
                ChangedOn = DateTime.Now,
                Message   = "Attachment Deleted",
                FilePath  = oldAttachment.FilePath,
                FileName  = oldAttachment.FileName
            };

            db.AttachmentHistories.Add(history);
            db.SaveChanges();
        }
        public ActionResult AttachmentDelete(int?id)
        {
            TicketAttachment attachments = db.TicketAttachments.Find(id);

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (attachments == null)
            {
                return(HttpNotFound());
            }
            return(View(attachments));
        }
Ejemplo n.º 17
0
        public ActionResult AddAttachment(int TicketId, TicketAttachment ticketAttachment)
        {
            if (ModelState.IsValid)
            {
                ticketAttachment.UserId   = User.Identity.GetUserId();
                ticketAttachment.TicketId = TicketId;
                db.TicketAttachments.Add(ticketAttachment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Titile", ticketComment.TicketId);
            //ViewBag.UserId = User.Identity.GetUserId();
            return(View(ticketAttachment));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Adds the pending attachment.
        /// </summary>
        /// <param name="ticketId">The ticket id for an existing ticket, or null if pending attachment is for a new ticket that hasn't been created yet.</param>
        /// <param name="file">The file.</param>
        /// <returns>the FileId of the pending attachment</returns>
        public int AddPendingAttachment(int?ticketId, TicketAttachment file)
        {
            if (ticketId.HasValue)
            {
                file.TicketId = ticketId.Value;
            }
            file.IsPending = true;

            file.UploadedBy   = Security.CurrentUserName;
            file.UploadedDate = DateTime.Now;

            Repository.AddPendingAttachment(file, true);

            return(file.FileId);
        }
        // GET: TicketAttachments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SubmitterName = db.Users.First(u => u.Id == ticketAttachment.UserId).DisplayName;
            return(View(ticketAttachment));
        }
        public ActionResult Details(int?id, bool flag)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserIndexFlag = flag;
            return(View(ticketAttachment));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,TicketId,Description,Created,UserId,FileUrl")] TicketAttachment ticketAttachment, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (FileValidation.IsWebFriendlyImage(file))
                {
                    var fileName = Path.GetFileName(file.FileName);
                    file.SaveAs(Path.Combine(Server.MapPath("~/uploads/"), fileName));
                    ticketAttachment.FileUrl = "/uploads/" + fileName;
                }
                var ticket      = db.Tickets.Find(ticketAttachment.TicketId);
                var sendeeemail = db.Users.Find(ticket.AssignedToUserId).Email;
                ticketAttachment.UserId  = User.Identity.GetUserId();
                ticketAttachment.Created = DateTime.Now;
                db.TicketAttachments.Add(ticketAttachment);
                db.SaveChanges();

                var callbackUrl = Url.Action("Details", "Tickets", new { id = ticketAttachment.TicketId }, protocol: Request.Url.Scheme);
                try
                {
                    EmailService    ems = new EmailService();
                    IdentityMessage msg = new IdentityMessage();

                    msg.Body        = "A new attachment has been added" + " to" + " ticket " + ticketAttachment.Ticket.Title + " on project " + ticketAttachment.Ticket.Project.Name + Environment.NewLine + "Please click the following link to view the details" + "<a href=\"" + callbackUrl + "\"> New Attachment</a>";
                    msg.Destination = sendeeemail;
                    msg.Subject     = "TicketAttachment";

                    TicketNotification ticketNotification = new TicketNotification();
                    ticketNotification.TicketId = ticketAttachment.TicketId;
                    ticketNotification.Created  = DateTime.Now;
                    ticketNotification.UserId   = User.Identity.GetUserId();
                    ticketNotification.Message  = msg.Body;
                    db.TicketNotifications.Add(ticketNotification);
                    db.SaveChanges();

                    await ems.SendMailAsync(msg);
                }
                catch (Exception ex)
                {
                    await Task.FromResult(0);
                }
                return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId }));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(RedirectToAction("index", "Tickets"));
        }
 public ActionResult Edit([Bind(Include = "Id,TicketId,UserId,FilePath,Description,Created,Updated")] TicketAttachment ticketAttachment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticketAttachment).State = EntityState.Modified;
         var userr = User.Identity.GetUserId();
         if (!rolesHelper.IsDemoUser(userr))
         {
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketAttachment.TicketId);
     ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
     return(View(ticketAttachment));
 }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Oops5", "Home", null));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(RedirectToAction("Oops5", "Home", null));
            }
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
Ejemplo n.º 24
0
        // GET: TicketAttachments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null || !db.TicketComments.Any(t => t.Id == id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.AuthorId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.AuthorId);
            //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId);
            return(View(ticketAttachment));
        }
        // GET: TicketAttachments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);

            if (ticketAttachment == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketAttachment.TicketId);
            //ViewBag.UserId = new SelectList(db.ApplicationUsers, "Id", "FirstName", ticketAttachment.UserId);
            return(View(ticketAttachment));
        }
Ejemplo n.º 26
0
        // GET: TicketAttachments/Create
        public ActionResult Create(int id)
        {
            var user       = db.Users.SingleOrDefault(u => u.UserName == User.Identity.Name);
            var attachment = new TicketAttachment
            {
                UserId   = user.Id,
                User     = user,
                TicketId = id,
                Ticket   = db.Tickets.Find(id),
                Created  = new DateTimeOffset(DateTime.Now)
            };

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title");
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName");
            return(View(attachment));
        }
Ejemplo n.º 27
0
        public void deleteTicketAttachment(TicketAttachment ticketAttachment)
        {
            FileInfo fi = new FileInfo(ticketAttachment.FilePath);
            var      di = fi.Directory;

            if (!di.Exists)
            {
                di.Create();
            }
            else
            {
                File.Delete(ticketAttachment.FilePath);
            }

            TicketAttachmentRepo.Delete(ticketAttachment);
        }
        public ActionResult AttachmentDeleteConfirmed(int id)
        {
            TicketAttachment attachments   = db.TicketAttachments.Find(id);
            TicketHistory    ticketHistory = new TicketHistory();


            ticketHistory.AuthorId = User.Identity.GetUserId();
            ticketHistory.Created  = DateTimeOffset.UtcNow;
            ticketHistory.TicketId = attachments.TicketId;
            ticketHistory.Property = "ATTACHMENT REMOVED";
            db.TicketHistories.Add(ticketHistory);
            db.TicketAttachments.Remove(attachments);
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = attachments.TicketId }));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            TicketAttachment ticketAttachment = db.TicketAttachments.Find(id);
            Ticket           ticket           = db.Tickets.First(t => t.Id == ticketAttachment.TicketId);
            Project          project          = db.Projects.Find(ticket.ProjectId);

            if ((User.IsInRole("Admin") ||
                 (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) ||
                 (User.IsInRole("Developer") && ticket.AssignedUserId == User.Identity.GetUserId()) ||
                 (User.IsInRole("Submitter") && ticket.OwnerUserId == User.Identity.GetUserId())) &&
                (ticket.IsArchived == false))
            {
                // Now delete from database
                db.TicketAttachments.Remove(ticketAttachment);
                db.SaveChanges();

                // Now delete the file from the repository
                var absPath = Server.MapPath(ticketAttachment.FileUrl);
                //att.SaveAs(Path.Combine(absPath, att.FileName));
                try {
                    System.IO.File.Delete(@absPath);
                }
                catch (System.IO.IOException e) {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    return(RedirectToAction("Details", "Tickets", new { id = ticket.Id }));
                }

                // Now add the TicketHistory for the TicketAttachment Deletion
                HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId());
                ticketHistory.AddHistoryEvent(ticketAttachment.TicketId, "Attachment Deleted", ticketAttachment.FileUrl, null);

                // Now send notification, if assignedUser != Current User
                if (ticket.AssignedUserId != null && ticket.AssignedUserId != User.Identity.GetUserId())
                {
                    List <string> attachments = new List <string>();
                    attachments.Add(ticketAttachment.FileName);
                    string             assignedUserEmailAddress = db.Users.Find(ticket.AssignedUserId).Email;
                    bool               attAdded     = false;
                    NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId());
                    await notification.AddAttachmentNotification(ticket.Id, attachments, attAdded, assignedUserEmailAddress);
                }

                return(RedirectToAction("Details", "Tickets", new { id = ticket.Id }));
            }
            return(RedirectToAction("Details", "Tickets", new { id = ticket.Id }));
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FormFile,Image,Description,Created,FileName,ContentType,FileData,TicketId,CustomUserId")] TicketAttachment ticketAttachment)
        {
            if (!(await _roleService.IsUserInRoleAsync(await _userManager.GetUserAsync(User), Roles.DemoUser.ToString())))
            {
                if (id != ticketAttachment.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        if (ticketAttachment.FormFile != null)
                        {
                            MemoryStream ms = new MemoryStream();
                            await ticketAttachment.FormFile.CopyToAsync(ms);

                            ticketAttachment.FileData    = ms.ToArray();
                            ticketAttachment.FileName    = ticketAttachment.FormFile.FileName;
                            ticketAttachment.ContentType = ticketAttachment.FormFile.ContentType;
                        }

                        ticketAttachment.Created      = DateTimeOffset.Now;
                        ticketAttachment.CustomUserId = _userManager.GetUserId(User);
                        _context.Update(ticketAttachment);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!TicketAttachmentExists(ticketAttachment.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction("Details", "Tickets", new { id }));
                }
                ViewData["CustomUserId"] = new SelectList(_context.Users, "Id", "Id", ticketAttachment.CustomUserId);
                ViewData["TicketId"]     = new SelectList(_context.Ticket, "Id", "Id", ticketAttachment.TicketId);
                return(View(ticketAttachment));
            }
            return(RedirectToAction("DemoUser", "Projects"));
        }
Ejemplo n.º 31
0
        public ActionResult DeleteAttachment(int id)
        {
            var user = db.Users.Find(User.Identity.GetUserId());
            TicketAttachment ticketattachment = db.TicketAttachments.Find(id);
            Ticket           ticket           = db.Tickets.Find(ticketattachment.TicketId);

            if ((User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && ticket.OwnerUserId == user.Id) || ticketattachment.AuthorId == user.Id))
            {
                db.TicketAttachments.Remove(ticketattachment);
                db.SaveChanges();
                return(RedirectToAction("Details", "Tickets", new { id = ticket.Id }));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }