예제 #1
0
        public ActionResult DeleteAttachment(TicketAttachmentsModel deleteAttachment, HttpPostedFileBase file) {

            if (ModelState.IsValid) {
                db.AttachmentData.Attach(deleteAttachment);
                db.AttachmentData.Remove(deleteAttachment);
                db.SaveChanges();
            }
            return RedirectToAction("Details", new { id = deleteAttachment.TicketId });
        }
예제 #2
0
        public async Task<ActionResult> Create([Bind(Include = "Id,Title,Description,CreatedDate,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId")] TicketsModel ticketsModel, HttpPostedFileBase file) {

            if (file != null && file.ContentLength > 0) {
                //Check the file name to make sure it's a image
                var ext = Path.GetExtension(file.FileName).ToLower();

                if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" &&
                    ext != ".bmp" && ext != ".txt" && ext != ".doc" && ext != ".docx" &&
                    ext != ".pdf" && ext != ".rtf" && ext != ".wps")
                    ModelState.AddModelError("image", "Invalid Image Type.");
            }

            TicketHistoriesModel histories = new TicketHistoriesModel();
            TicketAttachmentsModel attachments = new TicketAttachmentsModel();
            if (ModelState.IsValid) {

                if (file != null && file.ContentLength > 0) {
                    var filePath = "/Uploads/";
                    var absPath = Server.MapPath("~" + filePath);
                    attachments.FileUrl = filePath + file.FileName;
                    file.SaveAs(Path.Combine(absPath, file.FileName));
                    attachments.CreatedDate = DateTimeOffset.Now;
                    //attachments.Description = new at
                    attachments.UserId = ticketsModel.OwnerUserId;
                    db.AttachmentData.Add(attachments);
                }

                ticketsModel.CreatedDate = DateTimeOffset.Now;
                ticketsModel.UpdatedDate = null;
                if (ticketsModel.AssignedToUserId == null) {
                    //if ticket is unassigned when it is created it is assigned to the Project Manager
                    ticketsModel.AssignedToUserId = "43c6b827-3faf-4afa-bb24-7b937e623052";
                }
                
                db.TicketsData.Add(ticketsModel);
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            ViewBag.ProjectId = new SelectList(db.ProjectsData, "Id", "Name", ticketsModel.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPrioritiesData, "Id", "Name", ticketsModel.TicketPriorityId);
            ViewBag.TicketStatusId = new SelectList(db.TicketStatusesData, "Id", "Name", ticketsModel.TicketStatusId);
            ViewBag.TicketTypeId = new SelectList(db.TicketTypesData, "Id", "Name", ticketsModel.TicketTypeId);
            ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "DisplayName", ticketsModel.OwnerUserId);
            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "DisplayName", ticketsModel.AssignedToUserId);
            ViewBag.Comments = new SelectList(db.Users, "Id", "Comment", ticketsModel.Comments);
            ViewBag.Historys = new SelectList(db.TicketHistoriesData, "Id", "Property", ticketsModel.History);

            return View(ticketsModel);
        }
예제 #3
0
        public ActionResult EditAttachment(TicketAttachmentsModel editAttachment, HttpPostedFileBase file) {

            if (file != null && file.ContentLength > 0) {
                var ext = Path.GetExtension(file.FileName).ToLower();

                if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" &&
                    ext != ".bmp" && ext != ".txt" && ext != ".doc" && ext != ".docx" &&
                    ext != ".pdf" && ext != ".rtf" && ext != ".wps")
                    ModelState.AddModelError("image", "Invalid Image Type.");
            }

            if (ModelState.IsValid) {

                if (file != null && file.ContentLength > 0) {
                    var filePath = "/Uploads/";
                    var absPath = Server.MapPath("~" + filePath);
                    editAttachment.FileUrl = filePath + file.FileName;
                    file.SaveAs(Path.Combine(absPath, file.FileName));
                }

                editAttachment.UpdatedDate = System.DateTimeOffset.Now;
                editAttachment.UserId = User.Identity.GetUserId();
                db.AttachmentData.Attach(editAttachment);
                db.Entry(editAttachment).Property("Description").IsModified = true;
                db.Entry(editAttachment).Property("FileUrl").IsModified = true;
                db.Entry(editAttachment).Property("UpdatedDate").IsModified = true;
                db.Entry(editAttachment).Property("UserId").IsModified = true;

                db.SaveChanges();
            }
            return RedirectToAction("Details", new { id = editAttachment.TicketId });
        }