示例#1
0
        private void getPicture(ProductChildInitializer item, ProductChild pc)
        {
            IHasUploads pcHasuploads = pc as IHasUploads;

            pc.IsNullThrowException(string.Format("Programming Error. Product Child is not showing as IHasUploads. It is. Currently initializing '{0}'", item.ProductName));

            string originalname        = item.ProductName.RemoveAllSpaces().ToString();
            string relative_SrcPath    = pc.MiscFilesLocation_Initialization();
            string relative_targetPath = pc.MiscFilesLocation(UserName);

            string filenameNoExtention = getFileNameWithoutExtention(relative_SrcPath, originalname);


            if (!imageFileExists(filenameNoExtention))
            {
                return;
            }

            #region Copy File
            string originalnameWithoutExtention = originalname;
            List <UploadedFile> uploadedFileLst = new List <UploadedFile>();

            //copy the actual file to the new spot. We need to do it here so we can get it's new name
            //== COPY FILE
            string newNameWithMappedPathPlusExtention = CopyFile(relative_SrcPath, relative_targetPath, Path.ChangeExtension(originalnameWithoutExtention, ExtentionFound));

            //create the upload file
            UploadedFile uf = new UploadedFile(
                originalnameWithoutExtention,
                Path.GetFileNameWithoutExtension(newNameWithMappedPathPlusExtention),
                ExtentionFound,
                relative_targetPath);

            //add to uploadlist
            uploadedFileLst.Add(uf);

            #endregion
            if (!uploadedFileLst.IsNullOrEmpty())
            {
                foreach (UploadedFile file in uploadedFileLst)
                {
                    file.MetaData.Created.SetToTodaysDate(UserName, UserId);


                    //initializes navigation if it is null

                    //You need to add a refrence here to save the file in the UploadedFile as well.
                    file.ProductChild   = pc;
                    file.ProductChildId = pc.Id;

                    if (pcHasuploads.MiscFiles.IsNull())
                    {
                        pcHasuploads.MiscFiles = new List <UploadedFile>(); //intializing
                    }
                    pcHasuploads.MiscFiles.Add(file);

                    UploadedFileBiz.Create(CreateControllerCreateEditParameter(file as ICommonWithId));
                }
            }
        }
示例#2
0
        public override void Event_AddUploadedFileInfoIntoDb(IHasUploads entity, UploadObject uploadObj)
        {
            if (uploadObj.NumberOfFilesInFileList > 0)
            {
                foreach (var file in uploadObj.FileList)
                {
                    file.MetaData.Created.SetToTodaysDate(UserId, UserName);

                    file.MenuPath1   = entity as MenuPath1;
                    file.MenuPath1Id = entity.Id;

                    //add the owner of the file here....
                    entity.MiscFiles.Add(file);
                    UploadedFileBiz.Create(CreateControllerCreateEditParameter(file as ICommonWithId));
                }
            }
        }