Ejemplo n.º 1
0
        public async Task <IActionResult> Create([FromForm] UploadMediaRequestModel model)
        {
            if (model.File == null)
            {
                return(this.StatusCode((int)HttpStatusCode.UnprocessableEntity));
            }

            var organisationClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim);

            var serviceModel = new CreateMediaItemServiceModel
            {
                Username       = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value,
                OrganisationId = GuidHelper.ParseNullable(organisationClaim?.Value),
                Language       = CultureInfo.CurrentCulture.Name,
                File           = model.File
            };

            var validator = new CreateMediaItemModelValidator();

            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult.IsValid)
            {
                var mediaItemId = await this.mediaService.CreateFileAsync(serviceModel);

                return(this.StatusCode((int)HttpStatusCode.Created, new { Id = mediaItemId }));
            }

            return(this.StatusCode((int)HttpStatusCode.BadRequest));
        }
Ejemplo n.º 2
0
        public async Task <string> UploadFile(UploadMediaRequestModel uploadModel)
        {
            var url = _addressConfig.UploadMediaUrl;

            _client.QueryString.Add("type", uploadModel.MediaType.ToString().ToLower());
            var result = await _client.UploadOneFile(url, uploadModel.FileName);

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <string> uploadFile([FromBody] FileInfos fileInfos)
        {
            try
            {
                //var fileName = HttpContext.Current.Server.MapPath(fileInfos.FilePath);
                var fileName = fileInfos.FilePath;

                var uploadFileModel = new UploadMediaRequestModel()
                {
                    FileName  = fileName,
                    MediaType = UploadMediaType.File
                };
                string uploadModel = await dtManager.UploadFile(uploadFileModel);

                FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(uploadModel);

                //绑定路径信息
                fileInfos.MediaId         = fileSendModel.Media_Id;
                fileInfos.LastModifyState = "0";
                fileInfos.LastModifyTime  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                using (DDContext context = new DDContext())
                {
                    fileInfos.FilePath = @"\" + fileInfos.FilePath.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                    context.FileInfos.Add(fileInfos);
                    context.SaveChanges();
                }

                return(JsonConvert.SerializeObject(new ErrorModel
                {
                    errorCode = 0,
                    errorMessage = "上传盯盘成功"
                }));
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new ErrorModel
                {
                    errorCode = 1,
                    errorMessage = ex.Message
                }));
            }
        }
        public async Task <string> UploadMedia([FromBody] string Path)
        {
            var fileName = "";

            if (string.IsNullOrEmpty(Path))  //测试数据
            {
                fileName = HttpContext.Current.Server.MapPath("~/测试媒体文件/测试文本123.txt");
            }
            else
            {
                fileName = HttpContext.Current.Server.MapPath(Path);
            }
            var uploadFileModel = new UploadMediaRequestModel()
            {
                FileName  = fileName,
                MediaType = UploadMediaType.File
            };

            return(await dtManager.UploadFile(uploadFileModel));
        }
Ejemplo n.º 5
0
        public async Task <object> PostFile(FileModel fileModel)
        {
            try
            {
                string result = "";
                if (fileModel != null)
                {
                    string Base64String  = fileModel.Base64String.Replace("data:image/png;base64,", "");
                    byte[] FileContent   = Convert.FromBase64String(Base64String);
                    string ImageFilePath = AppDomain.CurrentDomain.BaseDirectory + "UploadFile\\Images\\ChangeImages\\";
                    string PdfFilePath   = AppDomain.CurrentDomain.BaseDirectory + "UploadFile\\Flies\\";
                    string FileName      = Path.GetFileName(fileModel.FileName.Substring(0, fileModel.FileName.Length - 4));
                    string Err           = "";
                    bool   upres         = WriteFile(ImageFilePath, FileContent, FileName + ".png", out Err);

                    if (upres)
                    {
                        //清除文件
                        File.Delete(PdfFilePath + FileName + ".PDF");
                        //生成PDF
                        PDFHelper.ConvertJpgToPdf(ImageFilePath + FileName + ".png", PdfFilePath + FileName + ".PDF");
                        //上盯盘
                        string fileName        = PdfFilePath + FileName + ".PDF";
                        var    uploadFileModel = new UploadMediaRequestModel()
                        {
                            FileName  = fileName,
                            MediaType = UploadMediaType.File
                        };
                        DingTalkManager dingTalkManager  = new DingTalkManager();
                        string          UploadFileResult = await dingTalkManager.UploadFile(uploadFileModel);

                        FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(UploadFileResult);
                        //替换数据库MediaId
                        using (DDContext context = new DDContext())
                        {
                            Tasks tasks = context.Tasks.Where(t => t.TaskId.ToString() == fileModel.TaskId && t.NodeId == 0).First();
                            tasks.MediaIdPDF = tasks.MediaIdPDF.Replace(fileModel.OldMediaId, fileSendModel.Media_Id);
                            result           = tasks.MediaIdPDF;
                            context.Entry <Tasks>(tasks).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        result = "上传文件写入失败:" + Err;
                    }
                }
                else
                {
                    result = "上传的文件信息不存在!";
                }
                return(new ErrorModel()
                {
                    errorCode = 0,
                    errorMessage = "保存成功",
                    Content = result
                });
            }
            catch (Exception ex)
            {
                return(new ErrorModel()
                {
                    errorCode = 1,
                    errorMessage = ex.Message
                });
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Index([FromForm] UploadMediaRequestModel model)
        {
            var importedOrderLines = this.orderFileService.ImportOrderLines(model.File);

            var basketItems = new List <BasketItem>();

            foreach (var orderLine in importedOrderLines)
            {
                var product = await this.productsRepository.GetProductAsync(
                    await HttpContext.GetTokenAsync(ApiExtensionsConstants.TokenName),
                    CultureInfo.CurrentUICulture.Name,
                    orderLine.Sku);

                if (product == null)
                {
                    this.logger.LogError($"Product for SKU {orderLine.Sku} and language {CultureInfo.CurrentUICulture.Name} couldn't be found.");
                }
                else
                {
                    var basketItem = new BasketItem
                    {
                        ProductId         = product.Id,
                        ProductSku        = product.Sku,
                        ProductName       = product.Name,
                        PictureUrl        = product.Images.OrEmptyIfNull().Any() ? this.mediaService.GetFileUrl(this.options.Value.MediaUrl, product.Images.First(), OrdersConstants.Basket.BasketProductImageMaxWidth, OrdersConstants.Basket.BasketProductImageMaxHeight, true) : null,
                        Quantity          = orderLine.Quantity,
                        ExternalReference = orderLine.ExternalReference,
                        DeliveryFrom      = orderLine.DeliveryFrom,
                        DeliveryTo        = orderLine.DeliveryTo,
                        MoreInfo          = orderLine.MoreInfo
                    };

                    basketItems.Add(basketItem);
                }
            }

            var basket = await this.basketRepository.SaveAsync(
                await HttpContext.GetTokenAsync(ApiExtensionsConstants.TokenName),
                CultureInfo.CurrentUICulture.Name,
                model.Id,
                basketItems);

            var basketResponseModel = new BasketResponseModel
            {
                Id = basket.Id
            };

            var productIds = basket.Items.OrEmptyIfNull().Select(x => x.ProductId.Value);

            if (productIds.OrEmptyIfNull().Any())
            {
                basketResponseModel.Items = basket.Items.OrEmptyIfNull().Select(x => new BasketItemResponseModel
                {
                    ProductId         = x.ProductId,
                    ProductUrl        = this.linkGenerator.GetPathByAction("Edit", "Product", new { Area = "Products", culture = CultureInfo.CurrentUICulture.Name, Id = x.ProductId }),
                    Name              = x.ProductName,
                    Sku               = x.ProductSku,
                    Quantity          = x.Quantity,
                    ExternalReference = x.ExternalReference,
                    ImageSrc          = x.PictureUrl,
                    ImageAlt          = x.ProductName,
                    DeliveryFrom      = x.DeliveryFrom,
                    DeliveryTo        = x.DeliveryTo,
                    MoreInfo          = x.MoreInfo
                });
            }

            return(this.StatusCode((int)HttpStatusCode.OK, basketResponseModel));
        }