Exemplo n.º 1
0
        public async Task <object> UploadFileAsync(IFormFile file, int key, int fileId, string guildId, int profileId, int profileType, string rootPath)
        {
            if (file == null || string.IsNullOrWhiteSpace(guildId))
            {
                return(null);
            }
            var    _type     = string.Empty;
            string deleteURL = string.Empty;
            //string root = Server.MapPath($"~{Utility.FileUtils._profile_parent_folder}");

            var result = null as FileModel;

            try
            {
                if (!BusinessExtensions.IsNotValidFileSize(file.Length))
                {
                    using (Stream stream = new MemoryStream())
                    {
                        await file.CopyToAsync(stream);

                        result = await UploadAsync(stream, key.ToString(), file.FileName, rootPath, Utility.FileUtils.GenerateProfileFolder());
                    }
                }
                if (result != null)
                {
                    var id = await _rpFile.Add(new ProfileFileAddSql
                    {
                        FileKey       = key,
                        FileName      = result.Name,
                        FilePath      = result.FileUrl,
                        Folder        = result.Folder,
                        ProfileId     = profileId,
                        ProfileTypeId = profileType,
                        GuidId        = guildId,
                        FileId        = fileId
                    });

                    deleteURL = $"/media/delete/{id.data}/{guildId}";
                }

                return(CreateConfig(result, key, deleteURL));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public async Task <object> UploadFileMcreditAsync(IFormFile file,
                                                          string rootPath,
                                                          int key,
                                                          int fileId,
                                                          string guildId,
                                                          int profileId,
                                                          string documentName,
                                                          string documentCode,
                                                          int documentId,
                                                          int groupId,
                                                          string mcId = null)
        {
            if (file == null || string.IsNullOrWhiteSpace(guildId))
            {
                return(null);
            }
            var    _type     = string.Empty;
            string deleteURL = string.Empty;
            var    result    = null as FileModel;

            try
            {
                if (!BusinessExtensions.IsNotValidFileSize(file.Length))
                {
                    using (Stream stream = new MemoryStream())
                    {
                        await file.CopyToAsync(stream);

                        result = await UploadAsync(stream, key.ToString(), file.FileName, rootPath, Utility.FileUtils.GenerateProfileFolderForMc());
                    }
                }
                if (result != null)
                {
                    var response = await _rpFile.AddMCredit(new MCProfileFileSqlModel
                    {
                        FileKey       = key,
                        FileName      = result.Name,
                        FilePath      = result.FileUrl,
                        Folder        = result.Folder,
                        ProfileId     = profileId,
                        ProfileTypeId = (int)ProfileType.MCredit,
                        GuidId        = guildId,
                        FileId        = fileId,
                        DocumentCode  = documentCode,
                        DocumentName  = documentName,
                        MC_DocumentId = documentId,
                        MC_GroupId    = groupId,
                        OrderId       = 0,
                        MC_MapBpmVar  = string.Empty,
                        McId          = mcId
                    });

                    deleteURL = $"/media/delete/{response.data}/{guildId}";
                }

                return(CreateConfig(result, key, deleteURL));
            }
            catch (Exception e)
            {
                return(null);
            }
        }