Beispiel #1
0
        public ProductImageComplex Create(ProductImageComplex source)
        {
            #region 取資料


            #endregion

            #region 邏輯驗證


            #endregion

            #region 變為Models需要之型別及邏輯資料
            List <ProductImage> children = GetChildOnCreate(source);
            //#endregion

            //#region Models資料庫

            foreach (ProductImage item in children)
            {
                this._Repository.Create(item);
            }

            this._UnitOfWork.SaveChange();
            #endregion

            return(this.Get(source.Product.ProductID));
        }
Beispiel #2
0
        private List <ProductImage> GetChildOnCreate(ProductImageComplex source)
        {
            List <ProductImage> infos = new List <ProductImage>();

            foreach (var item in source.ChildList)
            {
                ProductImage temp = Mapper.Map <ProductImage>(item);
                temp.LastPerson = IdentityService.GetUserData().UserID;
                temp.LastUpdate = DateTime.Now;
                infos.Add(temp);
            }
            return(infos);
        }
Beispiel #3
0
        public ProductImageComplex Get(string id)
        {
            ProductImageComplex info = new ProductImageComplex();

            info.Product = this._Product.Get(x => x.ProductID == id);

            var query2 =
                from u in this._Repository.GetAll()
                where (u.ProductID == id && u.Activate == InvoiceStatus.Valid.Value)
                select new ProductImageViewModel()
            {
                ImageID   = u.ImageID,
                ProductID = u.ProductID,
                ImagePath = u.ImagePath
            };

            info.ChildList = query2.ToList();

            return(info);
        }
        public ActionResult Edit(ProductImageComplex info, IEnumerable <HttpPostedFileBase> file)
        {
            ResultModel result = new ResultModel()
            {
                CloseWindow = false
            };

            try
            {
                #region 驗證Model
                if (!ModelState.IsValid)
                {
                    throw new Exception(ModelStateErrorClass.FormatToString(ModelState));
                }
                #endregion

                #region 前端資料變後端用資料ViewModel時用

                if (file != null && file.Count() > 0)
                {
                    string fileRootPath =
                        WebConfigurationManager.AppSettings["FileRootPath"];

                    string folder = $"{fileRootPath}\\{info.Product.ProductID}";
                    Directory.CreateDirectory(folder);

                    foreach (var item in file)
                    {
                        if (item != null)
                        {
                            string extension = Path.GetExtension(item.FileName);

                            var    fileName = $"{ Guid.NewGuid().ToString()}{extension}";
                            string path     = Path.Combine(folder, fileName);

                            info.ChildList.Add(
                                new ProductImageViewModel
                            {
                                ProductID = info.Product.ProductID,
                                ImagePath = path,
                                Activate  = InvoiceStatus.Valid.Value
                            });

                            item.SaveAs(path);
                        }
                    }
                }
                #endregion

                #region Service資料庫
                this._ProductImageComplexService.Create(info);
                #endregion

                #region  息頁面設定
                result.Status  = true;
                result.Url     = Url.Action("Index", "ProductImage", new { id = info.Product.ProductID });
                result.Message = "MessageComplete".ToLocalized();
                #endregion
            }
            catch (Exception ex)
            {
                #region  錯誤時錯誤訊息
                result.Status  = false;
                result.Message = ex.Message.ToString();
                #endregion
            }
            return(Json(result));
        }