Ejemplo n.º 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 override CompositionFetchResult GetCompositionData(ApplicationMetadata application, CompositionFetchRequest request, JObject currentData)
        {
            var compositionData = base.GetCompositionData(application, request, currentData);

            if (!compositionData.ResultObject.ContainsKey("attachment_"))
            {
                return(compositionData);
            }

            var attachments = compositionData.ResultObject["attachment_"].ResultList;

            foreach (var att in attachments)
            {
                var urlDescription = AttachmentHandler.BuildFileName(att["docinfo_.urlname"] as string);
                if (urlDescription == null)
                {
                    //keep description
                    att["urldescription"] = att["description"];
                }
                else
                {
                    att["urldescription"] = urlDescription;
                }
            }
            return(compositionData);
        }
 public async Task <IActionResult> Edit(int id, string projectName, IFormFile projectImage)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var attachmentHandler = new AttachmentHandler();
             var project           = attachmentHandler.AttachToProject(projectImage);
             project.Name = projectName;
             project.Id   = id;
             _context.Update(project);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!ProjectExists(id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View());
 }
        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));
        }
        // POST: TicketAttachments/Process
        public async Task <IActionResult> ProcessAttachment(IFormFile file, int ticketId)
        {
            var attachmentHandler = new AttachmentHandler();
            var ticketAttachment  = attachmentHandler.AttachToTicket(file, ticketId);

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

            return(RedirectToAction("Index", "Tickets"));
        }
        public async Task <IActionResult> Create([Bind("Name")] string projectName, IFormFile projectImage)
        {
            if (ModelState.IsValid)
            {
                var attachmentHandler = new AttachmentHandler();
                var project           = attachmentHandler.AttachToProject(projectImage);
                project.Name = projectName;
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        private void OnUpdate(List <Events.TickNametagData> nametags)
        {
            if (!IsDictionaryLoaded)
            {
                return;
            }

            if (Player.IsPlayingAnim(Dictionary, "PLYR_BUY_DRINK_PT1", 1))
            {
                if (Player.GetAnimCurrentTime(Dictionary, "PLYR_BUY_DRINK_PT1") > 0.1f)
                {
                    AttachmentHandler.Add("soda");
                }

                if (Player.GetAnimCurrentTime(Dictionary, "PLYR_BUY_DRINK_PT1") > 0.98f)
                {
                    Player.TaskPlayAnim(Dictionary, "PLYR_BUY_DRINK_PT2", 4f, -1000f, -1, 1048576, 0f, false, false, false);
                    Invoker.Invoke(0x2208438012482A1A, Player.Handle, false, false); // PED::_SET_PED_FAST_ANIMATIONS
                }
            }

            if (Player.IsPlayingAnim(Dictionary, "PLYR_BUY_DRINK_PT2", 1))
            {
                if (Player.GetAnimCurrentTime(Dictionary, "PLYR_BUY_DRINK_PT2") > 0.98f)
                {
                    Player.TaskPlayAnim(Dictionary, "PLYR_BUY_DRINK_PT3", 1000f, -4f, -1, 1048624, 0f, false, false, false);
                    Invoker.Invoke(0x2208438012482A1A, Player.Handle, false, false); // PED::_SET_PED_FAST_ANIMATIONS
                }
            }

            if (Player.IsPlayingAnim(Dictionary, "PLYR_BUY_DRINK_PT3", 1))
            {
                if (Player.GetAnimCurrentTime(Dictionary, "PLYR_BUY_DRINK_PT3") > 0.306f)
                {
                    AttachmentHandler.Remove("soda");
                }

                if (Player.GetAnimCurrentTime(Dictionary, "PLYR_BUY_DRINK_PT3") > 0.9f)
                {
                    Streaming.RemoveAnimDict(Dictionary);
                    Audio.ReleaseAmbientAudioBank();
                    IsDictionaryLoaded = false;
                    VendingMachineService.SetInUse(false);
                }
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Title,Description,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,DeveloperUserId")] Ticket ticket, List <IFormFile> attachments)
        {
            if (ModelState.IsValid)
            {
                // IF not demo user
                if (!User.IsInRole("Demo"))
                {
                    // Add file handler
                    ticket.OwnerUserId = _userManager.GetUserId(User);
                    ticket.Created     = DateTime.Now;
                    if (attachments != null)
                    {
                        foreach (var attachment in attachments)
                        {
                            AttachmentHandler attachmentHandler = new AttachmentHandler();
                            ticket.Attachments.Add(attachmentHandler.AttachToTicket(attachment, ticket.Id));
                        }
                    }
                    if (User.IsInRole("Submitter"))
                    {
                        ticket.TicketTypeId   = 1;
                        ticket.TicketStatusId = 1;
                    }
                    _context.Add(ticket);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    // Handle tempdata["DemoLockout"]
                    TempData["DemoLockout"] = "Your changes have not been saved. You must be logged in as a full user.";
                    //Handle redirect to index
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["DeveloperUserId"]  = new SelectList(_context.Users, "Id", "Id", ticket.DeveloperUserId);
            ViewData["OwnerUserId"]      = new SelectList(_context.Users, "Id", "Id", ticket.OwnerUserId);
            ViewData["ProjectId"]        = new SelectList(_context.Projects, "Id", "Name", ticket.ProjectId);
            ViewData["TicketPriorityId"] = new SelectList(_context.TicketPriorities, "Id", "Id", ticket.TicketPriorityId);
            ViewData["TicketStatusId"]   = new SelectList(_context.TicketStatuses, "Id", "Id", ticket.TicketStatusId);
            ViewData["TicketTypeId"]     = new SelectList(_context.TicketTypes, "Id", "Id", ticket.TicketTypeId);
            return(View(ticket));
        }
Ejemplo n.º 9
0
        private static List <Attachment> GetAttachments(CrudOperationData jsonObject)
        {
            var attachmentString = jsonObject.GetAttribute("newattachment") as string;
            var attachmentPath   = jsonObject.GetAttribute("newattachment_path") as string;
            var attachmentList   = new List <Attachment>();

            if (attachmentString != null && AttachmentHandler.Validate(attachmentPath, attachmentString))
            {
                var b64PartOnly = FileUtils.GetB64PartOnly(attachmentString);
                AttachmentHandler.ValidateNotEmpty(b64PartOnly);

                Log.DebugFormat("adding attachment. Name: {0}, Content:{1}", attachmentPath, attachmentString);

                attachmentList.Add(new Attachment {
                    AttachmentName = attachmentPath,
                    Attachment1    = b64PartOnly
                });
            }
            return(attachmentList);
        }
Ejemplo n.º 10
0
        private static void HandleCreationSummary(DataMap resultObject)
        {
            var list = resultObject.GetAttribute("attachment_");
            var sb   = new StringBuilder();

            foreach (var dictionary in (IEnumerable <Dictionary <string, object> >)list)
            {
                sb.Append("<p>");
                var urlDescription = AttachmentHandler.BuildFileName(dictionary["docinfo_.urlname"] as string);
                if (urlDescription == null)
                {
                    //keep description
                    dictionary["urldescription"] = dictionary["description"];
                }
                else
                {
                    dictionary["urldescription"] = urlDescription;
                }
                sb.Append(dictionary["urldescription"]);
                sb.Append("</p>");
            }
            resultObject.Attributes.Add("#attachmentsummary", sb.ToString());
        }
Ejemplo n.º 11
0
        public void GetDocument()
        {
            bool flag = false;

            ExTraceGlobals.MailCallTracer.TraceDebug((long)this.GetHashCode(), "DocumentEventHandler.GetDocument");
            base.ShowErrorInPage  = true;
            base.DontWriteHeaders = true;
            HttpContext httpContext = base.OwaContext.HttpContext;

            if (!DocumentLibraryUtilities.IsDocumentsAccessEnabled(base.UserContext))
            {
                throw new OwaSegmentationException("Access to this document library is disabled");
            }
            string text = (string)base.GetParameter("id");
            string s    = (string)base.GetParameter("URL");
            DocumentLibraryObjectId documentLibraryObjectId = DocumentLibraryUtilities.CreateDocumentLibraryObjectId(base.OwaContext);

            if (documentLibraryObjectId == null)
            {
                return;
            }
            try
            {
                this.DataBind(documentLibraryObjectId);
            }
            finally
            {
                if (this.stream == null)
                {
                    this.Dispose();
                }
            }
            if (this.stream == null)
            {
                return;
            }
            UserContext userContext = base.OwaContext.UserContext;

            AttachmentPolicy.Level levelForAttachment = AttachmentLevelLookup.GetLevelForAttachment(Path.GetExtension(this.fileName), this.contentType, userContext);
            if (base.IsParameterSet("allowLevel2"))
            {
                flag = true;
            }
            if (levelForAttachment == AttachmentPolicy.Level.Block)
            {
                string errorDescription = string.Format(CultureInfo.InvariantCulture, LocalizedStrings.GetNonEncoded(1280363351), new object[]
                {
                    this.fileName
                });
                Utilities.TransferToErrorPage(base.OwaContext, errorDescription, null, ThemeFileId.ButtonDialogInfo, true);
                return;
            }
            if (levelForAttachment == AttachmentPolicy.Level.ForceSave && !flag)
            {
                string queryStringParameter = Utilities.GetQueryStringParameter(httpContext.Request, "ns");
                string text2 = string.Concat(new string[]
                {
                    "<br> <a onclick=\"return false;\" href=\"ev.owa?ns=",
                    queryStringParameter,
                    "&ev=GetDoc&allowLevel2=1&URL=",
                    Utilities.UrlEncode(s),
                    "&id=",
                    Utilities.UrlEncode(documentLibraryObjectId.ToBase64String()),
                    Utilities.GetCanaryRequestParameter(),
                    "\">",
                    Utilities.HtmlEncode(this.fileName),
                    "</a>"
                });
                string errorDetailedDescription = string.Format(CultureInfo.InvariantCulture, LocalizedStrings.GetHtmlEncoded(-625229753), new object[]
                {
                    text2
                });
                Utilities.TransferToErrorPage(base.OwaContext, LocalizedStrings.GetHtmlEncoded(-226672911), errorDetailedDescription, ThemeFileId.ButtonDialogInfo, true, true);
                return;
            }
            int num = AttachmentHandler.SendDocumentContentToHttpStream(httpContext, this.stream, this.fileName, DocumentEventHandler.CalculateFileExtension(this.fileName), this.contentType);

            if (this.contentType != null && this.contentType.Equals("application/x-zip-compressed", StringComparison.OrdinalIgnoreCase))
            {
                Utilities.DisableContentEncodingForThisResponse(base.OwaContext.HttpContext.Response);
            }
            if (Globals.ArePerfCountersEnabled)
            {
                if ((documentLibraryObjectId.UriFlags & UriFlags.Sharepoint) != (UriFlags)0)
                {
                    OwaSingleCounters.WssBytes.IncrementBy((long)num);
                    OwaSingleCounters.WssRequests.Increment();
                    return;
                }
                if ((documentLibraryObjectId.UriFlags & UriFlags.Unc) != (UriFlags)0)
                {
                    OwaSingleCounters.UncBytes.IncrementBy((long)num);
                    OwaSingleCounters.UncRequests.Increment();
                }
            }
        }
 public AttachmentUpdate(AttachmentHandler <IObject, GameTime> AttachmentHandler)
 {
     this.AttachmentHandler = AttachmentHandler;
 }
 public AttachmentUpdate(AttachmentHandler<IObject, GameTime> AttachmentHandler)
 {
     this.AttachmentHandler = AttachmentHandler;
 }
Ejemplo n.º 14
0
        public async void CreatePost_RouteCreateViewModelIsValid_SectionAddedAndRedirectsToListAction()
        {
            // Arrange

            #region User Setup
            var userId1  = "0f8fad5b-d9cb-469f-a165-70867728950e";
            var userId2  = "ffffad5b-d9cb-469f-a165-70867728950e";
            var appUser1 = new ApplicationUser {
                DisplayName = "User1"
            };
            var appUser2 = new ApplicationUser {
                DisplayName = "User2"
            };
            UserService.Setup(service => service.FindByIdAsync(It.Is <string>(id => id.Equals(userId1))))
            .Returns(Task.FromResult(appUser1));
            UserService.Setup(service => service.FindByIdAsync(It.Is <string>(id => id.Equals(userId2))))
            .Returns(Task.FromResult(appUser2));
            #endregion

            #region File Setup
            string fakeWebRootPath = "fake/fakepath/veryfakepath/";
            HostingEnvironment.Setup(envi => envi.WebRootPath).Returns(fakeWebRootPath);

            string[] relativePaths =
            {
                "uploads/awidjqo.jpg"
            };

            IFormFileCollection formFileCollection = new FormFileCollection
            {
                new FormFile(Stream.Null, 0, 200, "Images/imageToDelete1", "imageToDelete1.jpg"),
                new FormFile(Stream.Null, 0, 200, "Images/imageToDelete2", "imageToDelete2.jpg"),
                new FormFile(Stream.Null, 0, 200, "Images/imageToUpload", "imageToUpload.jpg")
            };

            AttachmentHandler.Setup(
                handler => handler.SaveImagesOnServer(
                    It.Is <IList <IFormFile> >(
                        files => files.Intersect(formFileCollection).Count() == files.Count),
                    It.Is <string>(path => path.Equals(fakeWebRootPath)),
                    It.Is <string>(uploadPath => uploadPath.Equals("uploads"))))
            .Returns(Task.FromResult(relativePaths));

            var request = new Mock <HttpRequest>();
            request.SetupGet(x => x.Form["jfiler-items-exclude-Images-0"]).Returns("[\"imageToDelete1.jpg\",\"imageToDelete2.jpg\"]");
            request.SetupGet(x => x.Form.Files).Returns(formFileCollection);

            var context = new Mock <HttpContext>();
            context.SetupGet(x => x.Request).Returns(request.Object);
            RouteController.ControllerContext =
                new ControllerContext(new ActionContext(context.Object, new RouteData(), new ControllerActionDescriptor()));
            #endregion

            #region Route & ViewModel
            var viewModel = new RouteCreateViewModel
            {
                Note      = "This is a test note.",
                RouteID   = 1,
                GripColor = "000000",
                Type      = RouteType.Boulder,
                Builders  = new List <string>
                {
                    userId1,
                    userId2
                },
                Date = "14-12-2016",
                RouteDifficultyID = 1,
                RouteSectionID    = new List <int>
                {
                    1,
                    2
                },
                VideoUrl = "https://www.youtube.com/watch?v=bEYSyfEL8nY"
            };

            Route routeToCreate = new Route
            {
                Note       = viewModel.Note,
                RouteID    = viewModel.RouteID,
                GripColour = viewModel.GripColor,
                Type       = viewModel.Type
            };
            #endregion

            // Act
            IActionResult result = await RouteController.Create(viewModel);

            // Assert
            #region Assertions
            RouteService.Verify(service => service.AddRoute(It.Is <Route>(route => RouteEquals(route, routeToCreate)),
                                                            It.Is <string>(date => date.SequenceEqual(viewModel.Date)),
                                                            It.Is <int>(diff => diff == viewModel.RouteDifficultyID)),
                                Times.Once);

            RouteService.Verify(service => service.AddRouteToSections(It.Is <Route>(route => RouteEquals(route, routeToCreate)),
                                                                      It.Is <List <int> >(idList => idList.SequenceEqual(viewModel.RouteSectionID.ToList()))
                                                                      ),
                                Times.Once);

            RouteService.Verify(
                service => service.AddBuildersToRoute(It.Is <Route>(route => RouteEquals(route, routeToCreate)),
                                                      It.Is <ApplicationUser[]>(users => users.SequenceEqual(new[]
            {
                appUser1,
                appUser2
            })
                                                                                )),
                Times.Once);

            RouteService.Verify(service => service.AddAttachment(It.Is <Route>(route => RouteEquals(route, routeToCreate)),
                                                                 It.Is <string>(url => url.Equals(viewModel.VideoUrl)),
                                                                 It.Is <string[]>(paths => paths.SequenceEqual(relativePaths))
                                                                 ), Times.Once);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("Route", redirectToActionResult.ControllerName);
            Assert.Equal("List", redirectToActionResult.ActionName);
            #endregion
        }