コード例 #1
0
        public bool?Update(int key, TrackingRecordViewModel model, IDataSourceError error)
        {
            var trackingRecord = this.SingleOrDefault(key);

            if (trackingRecord == null)
            {
                return(null);
            }

            trackingRecord.ReferralTime = model.ReferralTime;
            trackingRecord.BustUp       = model.BustUp;
            trackingRecord.BustDown     = model.BustDown;
            trackingRecord.MilkCapacity = model.MilkCapacity;
            trackingRecord.Abdominal    = model.Abdominal;
            trackingRecord.Waist        = model.Waist;
            trackingRecord.Hip          = model.Hip;
            trackingRecord.LegLeft      = model.LegLeft;
            trackingRecord.LegRight     = model.LegRight;
            trackingRecord.Design       = model.Design;
            trackingRecord.Buy          = model.Buy;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #2
0
        public bool Create(CustomerViewModel model, IDataSourceError error)
        {
            if (this.CurrentUser.IsInRole("Company"))
            {
                error.Error.AppendLine("公司端不可新增");
                return(false);
            }

            var roleCustomer = this.userService.GetRoles().Where(r => r.Value.GetRoleType() == RoleType.Customer).SingleOrDefault();
            var customer     = new Customer
            {
                Name         = model.Name,
                Phone        = model.Phone,
                Birthday     = model.Birthday,
                Address      = model.Address,
                Introducer   = model.Introducer,
                ConsultantId = this.CurrentUserId,
                Height       = model.Height,
                Weight       = model.Weight,
                MemberRoleId = roleCustomer.Key
            };

            if (!string.IsNullOrEmpty(model.Career))
            {
                customer.Career = model.Career;
            }
            if (!string.IsNullOrEmpty(model.IdCardNumber))
            {
                customer.IdCardNumber = model.IdCardNumber;
            }
            if (!string.IsNullOrEmpty(model.Email))
            {
                customer.Email = model.Email;
            }
            if (!string.IsNullOrEmpty(model.LineId))
            {
                customer.LineId = model.LineId;
            }
            if (!string.IsNullOrEmpty(model.Remark))
            {
                customer.Remark = model.Remark;
            }

            this.DbContext.Customers.Add(customer);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.CustomerId = customer.CustomerId;
                result           = true;
            }
            catch { }

            return(result);
        }
コード例 #3
0
        //public void RefreshShipment(Shipment shipment)
        //{
        //    // 總計金額
        //    int totalAmount = 0;
        //    var shipmentDetails = this.DbContext.ShipmentDetails.Where(d => d.ShipmentId == shipment.ShipmentId).ToList();
        //    foreach (var shipmentDetail in shipmentDetails)
        //        totalAmount += shipmentDetail.SubtotalAmount;

        //    // 角色
        //    var roles = this.userService.GetRoles();
        //    WebApplication.Models.Role.Role role = WebApplication.Models.Role.Customer.GetInstance();
        //    if (shipment.CustomerId.HasValue)
        //    {
        //        var customer = this.DbContext.Customers.Where(c => c.CustomerId == shipment.CustomerId.Value).SingleOrDefault();
        //        if (customer != null && !string.IsNullOrEmpty(customer.MemberRoleId))
        //            role = roles[customer.MemberRoleId];
        //    }
        //    else
        //    {
        //        string cmdText = @"select ur.RoleId from AspNetUserRoles ur where ur.UserId = @UserId";
        //        string roleId = this.ExecuteScalar(cmdText, new SqlParameter("UserId", shipment.UserId)).ToString();
        //        role = roles[roleId];
        //    }

        //    // 消費回饋
        //    shipment.ConsumptionRebate = Convert.ToInt32(Math.Round(totalAmount * role.GetDiscount(), 0, MidpointRounding.AwayFromZero));
        //}

        public bool?Update(int key, ShipmentDetailViewModel model, IDataSourceError error)
        {
            var shipmentDetail = this.SingleOrDefault(key);

            if (shipmentDetail == null)
            {
                return(null);
            }

            int?price = null;

            if (model.Product != null && !string.IsNullOrEmpty(model.Product.Value))
            {
                shipmentDetail.ProductId = Convert.ToInt32(model.Product.Value);

                var product = this.DbContext.Products.Where(p => p.ProductId == shipmentDetail.ProductId).SingleOrDefault();
                if (product != null)
                {
                    price = product.Price;
                }
            }
            if (model.ProductDetail != null && !string.IsNullOrEmpty(model.ProductDetail.Value))
            {
                shipmentDetail.ProductDetailId = Convert.ToInt32(model.ProductDetail.Value);

                var productDetail = this.DbContext.ProductDetails.Where(d => d.ProductDetailId == shipmentDetail.ProductDetailId).SingleOrDefault();
                if (productDetail != null)
                {
                    price = productDetail.Price;
                }
            }

            if (!price.HasValue)
            {
                return(null);
            }

            shipmentDetail.Quantity       = model.Quantity;
            shipmentDetail.SubtotalAmount = price.Value * model.Quantity;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.SubtotalAmount = shipmentDetail.SubtotalAmount;
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #4
0
        public bool?Update(int key, CustomerViewModel model, IDataSourceError error)
        {
            var customer = this.SingleOrDefault(key);

            if (customer == null)
            {
                return(null);
            }

            customer.Name       = model.Name;
            customer.Phone      = model.Phone;
            customer.Birthday   = model.Birthday;
            customer.Address    = model.Address;
            customer.Introducer = model.Introducer;
            customer.Height     = model.Height;
            customer.Weight     = model.Weight;

            if (!string.IsNullOrEmpty(model.Career))
            {
                customer.Career = model.Career;
            }
            if (!string.IsNullOrEmpty(model.IdCardNumber))
            {
                customer.IdCardNumber = model.IdCardNumber;
            }
            if (!string.IsNullOrEmpty(model.Email))
            {
                customer.Email = model.Email;
            }
            if (!string.IsNullOrEmpty(model.LineId))
            {
                customer.LineId = model.LineId;
            }
            if (!string.IsNullOrEmpty(model.Remark))
            {
                customer.Remark = model.Remark;
            }

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #5
0
        public bool Create(SpecificationViewModel model, IDataSourceError error)
        {
            var specification = new ProductSpecification {
                Name = model.Text, ProductCategoryId = model.Parent
            };

            this.DbContext.ProductSpecifications.Add(specification);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.Value = specification.ProductSpecificationId;
                result      = true;
            }
            catch { }

            return(result);
        }
コード例 #6
0
        public bool Create(CategoryViewModel model, IDataSourceError error)
        {
            var category = new ProductCategory {
                Name = model.Text
            };

            this.DbContext.ProductCategories.Add(category);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.Value = category.ProductCategoryId;
                result      = true;
            }
            catch { }

            return(result);
        }
コード例 #7
0
        public bool Create(BodyViewModel model, IDataSourceError error)
        {
            if (this.CurrentUser.IsInRole("Company"))
            {
                error.Error.AppendLine("公司端不可新增");
                return(false);
            }

            var body = new Body
            {
                CustomerId               = model.CustomerId,
                HealthSpine              = model.HealthSpine,
                HealthBackPain           = model.HealthBackPain,
                HealthOther              = model.HealthOther,
                CurveChest               = model.CurveChest,
                CurveArm                 = model.CurveArm,
                CurveButtock             = model.CurveButtock,
                CurveStomachWaistAbdomen = model.CurveStomachWaistAbdomen,
                CurveThigh               = model.CurveThigh,
                CurveCalf                = model.CurveCalf,
                CurveFatSoft             = model.CurveFatSoft,
                CurveFatHard             = model.CurveFatHard,
                CurveFatOrange           = model.CurveFatOrange,
                CurveFatTangled          = model.CurveFatTangled,
                CurveFatOther            = model.CurveFatOther,
                Diagnosis                = model.Diagnosis
            };

            this.DbContext.Bodies.Add(body);
            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #8
0
        public bool Create(ProductViewModel model, IDataSourceError error)
        {
            var product = new Product
            {
                Name      = model.Name,
                Price     = model.Price,
                SafeStock = model.SafeStock
            };

            this.DbContext.Products.Add(product);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.ProductId = product.ProductId;
                result          = true;
            }
            catch { }

            return(result);
        }
コード例 #9
0
        public bool?Update(int key, CategoryViewModel model, IDataSourceError error)
        {
            var category = this.SingleOrDefault(key);

            if (category == null)
            {
                return(null);
            }

            category.Name = model.Text;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #10
0
ファイル: SkinService.cs プロジェクト: shengtai0201/TsaiJing
        public bool Create(SkinViewModel model, IDataSourceError error)
        {
            if (this.CurrentUser.IsInRole("Company"))
            {
                error.Error.AppendLine("公司端不可新增");
                return(false);
            }

            var skin = new Skin
            {
                CustomerId           = model.CustomerId,
                ConditionDry         = model.ConditionDry,
                ConditionOily        = model.ConditionOily,
                ConditionSensitivity = model.ConditionSensitivity,
                ConditionMixed       = model.ConditionMixed,
                ImproveAcne          = model.ImproveAcne,
                ImproveSensitive     = model.ImproveSensitive,
                ImproveWrinkle       = model.ImproveWrinkle,
                ImproveLargePores    = model.ImproveLargePores,
                ImproveSpot          = model.ImproveSpot,
                ImproveDull          = model.ImproveDull,
                ImprovePock          = model.ImprovePock,
                ImproveOther         = model.ImproveOther,
                Advice = model.Advice,
                Detail = model.Detail
            };

            this.DbContext.Skins.Add(skin);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #11
0
        public bool?Update(int key, BodyViewModel model, IDataSourceError error)
        {
            var body = this.SingleOrDefault(key);

            if (body == null)
            {
                return(this.Create(model, error));
            }
            else
            {
                body.HealthSpine              = model.HealthSpine;
                body.HealthBackPain           = model.HealthBackPain;
                body.HealthOther              = model.HealthOther;
                body.CurveChest               = model.CurveChest;
                body.CurveArm                 = model.CurveArm;
                body.CurveButtock             = model.CurveButtock;
                body.CurveStomachWaistAbdomen = model.CurveStomachWaistAbdomen;
                body.CurveThigh               = model.CurveThigh;
                body.CurveCalf                = model.CurveCalf;
                body.CurveFatSoft             = model.CurveFatSoft;
                body.CurveFatHard             = model.CurveFatHard;
                body.CurveFatOrange           = model.CurveFatOrange;
                body.CurveFatTangled          = model.CurveFatTangled;
                body.CurveFatOther            = model.CurveFatOther;
                body.Diagnosis                = model.Diagnosis;
            }

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #12
0
        public bool?Update(int key, SpecificationViewModel model, IDataSourceError error)
        {
            var specification = this.SingleOrDefault(key);

            if (specification == null)
            {
                return(null);
            }

            specification.Name = model.Text;
            specification.ProductCategoryId = model.Parent;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #13
0
        public bool?UpdateMember(int key, MemberViewModel model, IDataSourceError error)
        {
            var member = this.SingleOrDefault(key);

            if (member == null)
            {
                return(null);
            }

            member.Name       = model.Name;
            member.Email      = model.Email;
            member.Birthday   = model.Birthday;
            member.Phone      = model.Phone;
            member.Mobile     = model.Mobile;
            member.Address    = model.Address;
            member.Introducer = model.Introducer;

            if (!member.MemberDate.HasValue && member.MemberRoleId != model.MemberRole.Value)
            {
                member.MemberDate = DateTime.Now;
            }

            member.MemberRoleId = model.MemberRole.Value;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();

                model.JoinDate = member.MemberDate;
                result         = true;
            }
            catch { }

            return(result);
        }
コード例 #14
0
ファイル: SkinService.cs プロジェクト: shengtai0201/TsaiJing
        public bool?Update(int key, SkinViewModel model, IDataSourceError error)
        {
            var skin = this.SingleOrDefault(key);

            if (skin == null)
            {
                return(this.Create(model, error));
            }
            else
            {
                skin.ConditionDry         = model.ConditionDry;
                skin.ConditionOily        = model.ConditionOily;
                skin.ConditionSensitivity = model.ConditionSensitivity;
                skin.ConditionMixed       = model.ConditionMixed;
                skin.ImproveAcne          = model.ImproveAcne;
                skin.ImproveSensitive     = model.ImproveSensitive;
                skin.ImproveWrinkle       = model.ImproveWrinkle;
                skin.ImproveLargePores    = model.ImproveLargePores;
                skin.ImproveSpot          = model.ImproveSpot;
                skin.ImproveDull          = model.ImproveDull;
                skin.ImprovePock          = model.ImprovePock;
                skin.ImproveOther         = model.ImproveOther;
                skin.Advice = model.Advice;
                skin.Detail = model.Detail;
            }

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #15
0
        public bool Create(TrackingRecordViewModel model, IDataSourceError error)
        {
            if (this.CurrentUser.IsInRole("Company"))
            {
                error.Error.AppendLine("公司端不可新增");
                return(false);
            }

            var trackingRecord = new TrackingRecord
            {
                CustomerId   = model.CustomerId,
                ReferralTime = model.ReferralTime,
                BustUp       = model.BustUp,
                BustDown     = model.BustDown,
                MilkCapacity = model.MilkCapacity,
                Abdominal    = model.Abdominal,
                Waist        = model.Waist,
                Hip          = model.Hip,
                LegLeft      = model.LegLeft,
                LegRight     = model.LegRight,
                Design       = model.Design,
                Buy          = model.Buy
            };

            this.DbContext.TrackingRecords.Add(trackingRecord);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.TrackingRecordId = trackingRecord.TrackingRecordId;
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #16
0
        public bool?Update(int key, PurchaseViewModel model, IDataSourceError error)
        {
            var purchase = this.SingleOrDefault(key);

            if (purchase == null)
            {
                return(null);
            }

            purchase.ManufacturerId = Convert.ToInt32(model.Manufacturer.Value);
            purchase.Date           = model.Date;
            purchase.Remark         = model.Remark;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #17
0
        public bool?Update(int key, ProductViewModel model, IDataSourceError error)
        {
            var product = this.SingleOrDefault(key);

            if (product == null)
            {
                return(null);
            }

            product.Name      = model.Name;
            product.Price     = model.Price;
            product.SafeStock = model.SafeStock;

            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
コード例 #18
0
        public bool Create(PurchaseViewModel model, IDataSourceError error)
        {
            var purchase = new Purchase
            {
                ManufacturerId = Convert.ToInt32(model.Manufacturer.Value),
                UserId         = this.CurrentUserId,
                Date           = model.Date,
                Remark         = model.Remark
            };

            this.DbContext.Purchases.Add(purchase);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.PurchaseId  = purchase.PurchaseId;
                model.TotalAmount = 0;
                result            = true;
            }
            catch { }

            return(result);
        }
コード例 #19
0
        //public IShipmentService ShipmentService { get; set; }

        public bool Create(ShipmentDetailViewModel model, IDataSourceError error)
        {
            var shipmentDetail = new ShipmentDetail
            {
                ShipmentId = model.ShipmentId,
                ProductId  = Convert.ToInt32(model.Product.Value),
                Quantity   = model.Quantity
            };

            if (model.ProductDetail != null && !string.IsNullOrEmpty(model.ProductDetail.Value))
            {
                shipmentDetail.ProductDetailId = Convert.ToInt32(model.ProductDetail.Value);
            }

            // 存量檢查
            int quantity = 0, inventory = 0, safeStock = 0;     // 已出貨量, 已進貨量, 安全存量

            if (model.ProductDetail != null && !string.IsNullOrEmpty(model.ProductDetail.Value))
            {
                int productDetailId = Convert.ToInt32(model.ProductDetail.Value);

                // 已出貨量
                foreach (var sd in this.DbContext.ShipmentDetails.Where(d => d.ProductDetailId == productDetailId))
                {
                    quantity += sd.Quantity;
                }

                // 已進貨量
                foreach (var pd in this.DbContext.PurchaseDetails.Where(d => d.ProductDetailId == productDetailId))
                {
                    inventory += pd.Inventory;
                }

                // 安全存量
                var productDetail = this.DbContext.ProductDetails.Where(d => d.ProductDetailId == productDetailId).SingleOrDefault();
                safeStock = productDetail.SafeStock;

                shipmentDetail.SubtotalAmount = model.Quantity * productDetail.Price;
            }
            else if (model.Product != null && !string.IsNullOrEmpty(model.Product.Value))
            {
                int productId = Convert.ToInt32(model.Product.Value);

                // 已出貨量
                foreach (var sd in this.DbContext.ShipmentDetails.Where(d => d.ProductId == productId))
                {
                    quantity += sd.Quantity;
                }

                // 已進貨量
                foreach (var pd in this.DbContext.PurchaseDetails.Where(d => d.ProductId == productId))
                {
                    inventory += pd.Inventory;
                }

                // 安全存量
                var product = this.DbContext.Products.Where(p => p.ProductId == productId).SingleOrDefault();
                safeStock = product.SafeStock.Value;

                shipmentDetail.SubtotalAmount = model.Quantity * product.Price.Value;
            }

            //TransactionScope transaction = new TransactionScope();
            this.DbContext.ShipmentDetails.Add(shipmentDetail);
            var result = false;

            if (inventory >= (quantity + model.Quantity))
            {
                if ((inventory - (quantity + model.Quantity)) < safeStock)
                {
                    error.Error.AppendLine("存貨數量低於安全數量,但可出貨。");
                }

                try
                {
                    this.DbContext.SaveChanges();
                    model.ShipmentDetailId = shipmentDetail.ShipmentDetailId;
                    model.SubtotalAmount   = shipmentDetail.SubtotalAmount;
                    result = true;
                }
                catch { }

                //if (result)
                //    result = this.ShipmentService.RefreshShipment(shipmentDetail.ShipmentId) ?? false;
            }
            else
            {
                error.Error.AppendLine("出貨超過存貨數量,無法出貨。");
            }

            //if (result)
            //    transaction.Complete();

            //transaction.Dispose();
            return(result);
        }