Ejemplo n.º 1
0
        public static void ProcessRequest(LoginUser loginUser, int organizationID, HttpContext context, int?_id, string _ratingImage, List <string> segments)
        {
            int id;

            if (int.TryParse(segments[segments.Count - 1], out id))
            {
                _id = id;
                segments.RemoveAt(segments.Count - 1);
            }

            if (segments[segments.Count - 1] == "ratingpositive" || segments[segments.Count - 1] == "ratingneutral" || segments[segments.Count - 1] == "ratingnegative")
            {
                _ratingImage = segments[segments.Count - 1];
                segments.RemoveAt(segments.Count - 1);
            }


            AttachmentPath.Folder folder = GetFolder(context, segments.ToArray());
            if (folder == AttachmentPath.Folder.None)
            {
                throw new Exception("Invalid path.");
            }

            AttachmentProxy.References refType = AttachmentPath.GetFolderReferenceType(folder);
            if (refType == AttachmentProxy.References.None)
            {
                SaveFilesOld(loginUser, organizationID, _id, _ratingImage, context, folder);
            }
            else
            {
                SaveFiles(loginUser, context, folder, organizationID, _id);
            }
        }
Ejemplo n.º 2
0
        static void SaveFiles(LoginUser loginUser, HttpContext context, AttachmentPath.Folder folder, int organizationID, int?itemID)
        {
            List <TeamSupport.Handlers.UploadResult> result = new List <TeamSupport.Handlers.UploadResult>();

            AttachmentProxy.References refType = AttachmentPath.GetFolderReferenceType(folder);

            string path = AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, folder, 3);

            if (itemID != null)
            {
                path = Path.Combine(path, itemID.ToString());
            }
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            HttpFileCollection files = context.Request.Files;

            for (int i = 0; i < files.Count; i++)
            {
                if (files[i].ContentLength > 0)
                {
                    string fileName = TeamSupport.Handlers.UploadUtils.RemoveSpecialCharacters(DataUtils.VerifyUniqueUrlFileName(path, Path.GetFileName(files[i].FileName)));

                    files[i].SaveAs(Path.Combine(path, fileName));
                    if (refType != AttachmentProxy.References.None && itemID != null)
                    {
                        Attachment attachment = (new Attachments(loginUser)).AddNewAttachment();
                        attachment.RefType        = refType;
                        attachment.RefID          = (int)itemID;
                        attachment.OrganizationID = organizationID;
                        attachment.FileName       = fileName;
                        attachment.Path           = Path.Combine(path, fileName);
                        attachment.FileType       = files[i].ContentType;
                        attachment.FileSize       = files[i].ContentLength;
                        attachment.FilePathID     = 3;
                        if (context.Request.Form["description"] != null)
                        {
                            attachment.Description = context.Request.Form["description"].Replace("\n", "<br />");
                        }
                        if (context.Request.Form["productFamilyID"] != null && context.Request.Form["productFamilyID"] != "-1")
                        {
                            attachment.ProductFamilyID = Int32.Parse(context.Request.Form["productFamilyID"]);
                        }

                        attachment.Collection.Save();
                        result.Add(new TeamSupport.Handlers.UploadResult(fileName, attachment.FileType, attachment.FileSize, attachment.AttachmentID));
                    }
                    else
                    {
                        switch (refType)
                        {
                        default:
                            break;
                        }
                    }
                }
            }
            context.Response.Clear();
            context.Response.ContentType = "text/plain";
            context.Response.Write(DataUtils.ObjectToJson(result.ToArray()));
        }