Example #1
0
        /// <summary>
        /// 上傳圖片共用
        /// </summary>
        /// <param name="ImageModel">The image model.</param>
        /// <returns>fileUploadPath</returns>
        private CiResult <string> FileUpload(List <UploadViewModel> ImageModel)
        {
            var result = new CiResult <string> {
                IsSuccess = true
            };

            if (ImageModel != null)
            {
                //old
                if (ImageModel[0].FileStatus != FileStatus.Delete)
                {
                    result.Data = ImageModel[0].FilePath;
                }

                //fileUpload
                if (ImageModel[0].FileUpload != null)
                {
                    var fileFolder   = UploadTool.GetFileFolder(SessionManager.Client.SystemName, SourceType.System);
                    var uploadResult = UploadTool.FileUpload(ImageModel[0].FileUpload, ImageModel[0].FileType, fileFolder);
                    if (!uploadResult.IsSuccess)
                    {
                        result.Message   = uploadResult.Message;
                        result.IsSuccess = false;
                    }
                    else
                    {
                        result.Data = uploadResult.Data.FilePath;
                    }
                }
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Item圖片上傳
        /// </summary>
        /// <param name="upload">The upload.</param>
        /// <param name="filetype">The filetype.</param>
        /// <param name="sourceType">Type of the source.</param>
        /// <param name="sort">The sort.</param>
        /// <returns></returns>
        private CiResult <cms_ItemFile> ItemFileUpload(HttpPostedFileBase upload, FileType filetype, SourceType sourceType, int imageWidth = 0, int imageHeight = 0, int sort = 0, string subject = "")
        {
            var result = new CiResult <cms_ItemFile>();

            var fileFolder   = UploadTool.GetFileFolder(SessionManager.Client.SystemName, sourceType);
            var uploadResult = UploadTool.FileUpload(upload, filetype, fileFolder, true, imageWidth, imageHeight);

            if (!uploadResult.IsSuccess)
            {
                result.Message = uploadResult.Message;
            }
            else
            {
                uploadResult.Data.Subject = subject;
                result.Data      = ToIitemFile(uploadResult.Data, sourceType, sort);
                result.IsSuccess = true;
            }

            return(result);
        }
Example #3
0
        private async Task <ActionResult> OrderUpdate(EditOrderViewModel model, HttpPostedFileBase file = null, bool sendMail = true)
        {
            var result = new CiResult <OrderStatus>();
            var item   = itemService.Get(model.OrderViewModel.Order.ItemID.Value);

            // 訂購商品前檢查 (Admin不檢查)
            var preCheck = new CiResult();

            if (SessionManager.AccountType == AccountType.Member)
            {
                preCheck = service.ItemPreCheck(SessionManager.UserID, item, checkStock: false);
                if (!preCheck.IsSuccess)
                {
                    return(ErrorPage()); //404
                }
            }
            model.IsAdmin = (SessionManager.AccountType == AccountType.Admin);

            //set Data
            if (model.OrderViewModel.User == null)
            {
                model.OrderViewModel.User = new mgt_User();
            }
            model.OrderViewModel.User.ID           = SessionManager.UserID;
            model.OrderViewModel.Order.StructureID = item.StructureID;

            //fileUpload (image)
            if (file != null)
            {
                var fileFolder   = UploadTool.GetFileFolder(ApplicationHelper.SystemName, SourceType.MemberOrder);
                var uploadResult = UploadTool.FileUpload(file, FileType.Images, fileFolder);
                if (!uploadResult.IsSuccess)
                {
                    result.Message = uploadResult.Message;
                }
                else
                {
                    model.OrderViewModel.Order.FilePath = uploadResult.Data.FilePath;
                }
            }
            //fileUpload (audio)
            if (model.OrderViewModel.OrderDetails != null)
            {
                var fileFolder = UploadTool.GetFileFolder(ApplicationHelper.SystemName, SourceType.MemberOrder);
                foreach (var detail in model.OrderViewModel.OrderDetails)
                {
                    if (detail.FileUpload != null)
                    {
                        var uploadResult = UploadTool.FileUpload(detail.FileUpload, FileType.Audio, fileFolder);
                        if (!uploadResult.IsSuccess)
                        {
                            result.Message = uploadResult.Message;
                        }
                        else
                        {
                            detail.FilePath = uploadResult.Data.FilePath;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(result.Message))
            {
                result = service.Update(model, ApplicationHelper.DefaultLanguage);
            }

            //通知信 (no use?)
            if (sendMail)
            {
                var mailService = new MailService(ApplicationHelper.ClientID);
                if (result.IsSuccess)
                {
                    SessionManager.TempOrderID = result.ID;
                    await SendOrderMail(result.ID, model.OrderViewModel.Order.StructureID, (SystemMailType)result.Data, SessionManager.UserID);
                }
            }

            return(Json(result));
        }