예제 #1
0
        /// <summary>
        /// 新增並回傳
        /// </summary>
        /// <returns></returns>
        public PackagesModel CreateAndReturn()
        {
            PackagesModel _PackagesModel = new PackagesModel();

            if (this.Create())
            {
                _PackagesModel = GetPackageDetail(this.PackagesNo);
            }
            return(_PackagesModel);
        }
예제 #2
0
        /// <summary>
        /// 取得包裝明細
        /// </summary>
        /// <param name="PackagesNo">包裝編號</param>
        /// <returns></returns>
        public static PackagesModel GetPackageDetail(string PackagesNo)
        {
            PackagesModel _PackagesModel = new PackagesModel();

            using (var context = new EG_MagicCubeEntities())
            {
                if (context.Packages.Count() > 0)
                {
                    var Guid_PackagesNo = Guid.Parse(PackagesNo.ToUpper());
                    var r_Packages      = context?.Packages?.AsQueryable()?.Where(f => f.IsDel != "Y" && f.PackagesNo == Guid_PackagesNo).Select(c => c).FirstOrDefault();

                    if (r_Packages != null)
                    {
                        var _PackageItems   = context?.PackageItems?.AsQueryable()?.Where(pi => pi.PackagesNo == r_Packages.PackagesNo && pi.Works.IsDel != "Y").Select(c => c).ToList();
                        int _ItemAmount     = 0;
                        int _JoinItemAmount = 0;
                        int _Summary        = 0;
                        int _SumCost        = 0;
                        _ItemAmount                 = (_PackageItems?.Count()).Value;
                        _JoinItemAmount             = (_PackageItems?.Where(pi => pi.IsJoin == "Y").Count()).Value;
                        _Summary                    = _PackageItems.Where(pi => pi.IsJoin == "Y").Select(c => c.Works.Price).Sum();
                        _SumCost                    = _PackageItems.Where(pi => pi.IsJoin == "Y").Select(c => c.Works.Cost).Sum();
                        _PackagesModel.PackagesNo   = r_Packages.PackagesNo.ToString();
                        _PackagesModel.QRImg        = "";
                        _PackagesModel.PackagesName = r_Packages.PackagesName;
                        _PackagesModel.EndDate      = r_Packages.EndDate;
                        _PackagesModel.PackingDate  = r_Packages.PackingDate;
                        _PackagesModel.CreateDate   = r_Packages.CreateDate;
                        _PackagesModel.CreateUser   = r_Packages.CreateUser;
                        _PackagesModel.ModifyUser   = r_Packages.ModifyUser;
                        _PackagesModel.ModifyDate   = r_Packages.ModifyDate;
                        _PackagesModel.SearchJson   = r_Packages.SearchJson;
                        _PackagesModel.PackagesMemo = r_Packages.PackagesMemo;
                        _PackagesModel.ItemAmount   = _JoinItemAmount.ToString() + " (" + _ItemAmount.ToString() + ")";
                        _PackagesModel.Budget       = r_Packages.Budget;
                        _PackagesModel.SumCost      = _SumCost;
                        _PackagesModel.SumPrice     = _Summary;
                        _PackagesModel.PackageItems = ReturnPackageItemList(PackagesNo, true);
                        //PackageItems = c.PackageItems.Select(pi => new PackageItemModel()
                        //{
                        //    WorksNo = pi.WorksNo.ToString(),
                        //    WorksName = pi.Works.WorksName,
                        //    Price = pi.Works.Price,
                        //    AuthorsName = pi.Works.WorksAuthors.FirstOrDefault().Authors.AuthorsCName,
                        //    IsJoin = pi.IsJoin
                        //}
                        //).ToList()
                    }
                }
            }

            return(_PackagesModel);
        }
예제 #3
0
        /// <summary>
        /// 以包裝資料更新
        /// </summary>
        /// <param name="newPackages">新包裝資料</param>
        /// <returns></returns>
        public static bool Update(PackagesModel newPackages)
        {
            using (var context = new EG_MagicCubeEntities())
            {
                var Guid_PackagesNo = Guid.Parse(newPackages.PackagesNo.ToUpper());
                var oldPackages     = context.Packages.AsQueryable().First(x => x.PackagesNo == Guid_PackagesNo);
                if (oldPackages != null)
                {
                    if (!string.IsNullOrEmpty(newPackages.PackagesName))
                    {
                        oldPackages.PackagesName = newPackages.PackagesName;
                    }
                    oldPackages.PackingDate  = newPackages.PackingDate;
                    oldPackages.EndDate      = newPackages.EndDate;
                    oldPackages.ModifyUser   = HttpContext.Current?.User?.Identity?.Name ?? "";
                    oldPackages.ModifyDate   = newPackages.ModifyDate;
                    oldPackages.PackagesMemo = newPackages.PackagesMemo;
                    oldPackages.SearchJson   = newPackages.SearchJson;
                    oldPackages.Budget       = newPackages.Budget;
                    var _PackageItems = context.PackageItems.AsQueryable().Where(c => c.PackagesNo == oldPackages.PackagesNo).ToList();
                    foreach (PackageItemModel _PackageItemModel in newPackages.PackageItems)
                    {
                        var Guid_WorksNo     = Guid.Parse(_PackageItemModel.WorksNo.ToUpper());
                        int PackageItemCount = _PackageItems.Where(c => c.WorksNo == Guid_WorksNo).Count();
                        if (PackageItemCount == 0)
                        {
                            context.PackageItems.Add(new PackageItems()
                            {
                                PackagesNo = oldPackages.PackagesNo,
                                WorksNo    = Guid_WorksNo,
                                JoinDate   = DateTime.Now,
                                IsJoin     = _PackageItemModel.IsJoin,
                                DelDate    = new Nullable <DateTime>()
                            });
                        }
                    }
                    if (context.SaveChanges() == 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }