예제 #1
0
        private async Task <IActionResult> DoSell(SellToCustomerViewModel model)
        {
            var loginUser = await GetCurrentUserAsync();

            ProductDesc productDesc = await _applicationDbContext.ProductDesc
                                      .Where(m => m.ID.Equals(model.MattressTypeID,
                                                              StringComparison.InvariantCultureIgnoreCase))
                                      .FirstOrDefaultAsync();

            Mattress mattress = new Mattress
            {
                ID           = model.MattressID,
                TypeDesc     = productDesc,
                RegisterDate = model.SaleDate,
                SaleDate     = model.SaleDate,
            };

            SaleToCustomerDetail saleToCustomerDetail = new SaleToCustomerDetail
            {
                Gifts           = model.Gifts,
                DeliveryAddress = model.DeliveryAddress,
                Prodect         = mattress,
                Price           = productDesc.Price
            };
            SaleToCustomer saleToCustomer = new SaleToCustomer
            {
                ID       = IDGenerator.GetSaleToCustomerIDGenerator(_applicationDbContext).GetNext(),
                Customer = new Member {
                    MemberID = model.CustomerID
                },
                SellingAgents = new Member {
                    MemberID = loginUser.UserName
                },
                DealDate = model.SaleDate,
            };

            saleToCustomerDetail.Sale = saleToCustomer;
            saleToCustomer.DetailItems.Add(saleToCustomerDetail);

            _applicationDbContext.Mattress.Add(mattress);
            _applicationDbContext.SaleToCustomer.Add(saleToCustomer);
            _applicationDbContext.SaleToCustomeDetails.Add(saleToCustomerDetail);

            var pointItems = await AddMemberPoint(saleToCustomerDetail);

            _applicationDbContext.SaveChanges();

            return(Json(new {
                saleToCustomerID = saleToCustomer.ID,
                memberPointItems = pointItems,
                sellMattressData = new {
                    MattressID = mattress.ID,
                    MattressTypeName = mattress.TypeDesc.Name,
                    DeliveryAddress = saleToCustomerDetail.DeliveryAddress,
                    CustomerID = saleToCustomer.Customer.MemberID,
                    SaleDate = saleToCustomer.DealDate.Date.ToString("yyyy'-'MM'-'dd"),
                    Gifts = saleToCustomerDetail.Gifts
                }
            }));
        }
예제 #2
0
파일: Bed.cs 프로젝트: davidbedok/oeprog2
 public Bed(String fancyName, Room room, Material material, Size size, double price, Mattress mattress, bool doubleSize, bool compactSize,
         bool builtInLamp)
     : base(fancyName, room, material, size, price)
 {
     this.mattress = mattress;
     this.doubleSize = doubleSize;
     this.compactSize = compactSize;
     this.builtInLamp = builtInLamp;
 }
예제 #3
0
        private async Task <ActionResult> DoSell(SellToCustomerViewModel model)
        {
            var loginUser = await GetCurrentUserAsync();

            ProductDesc productDesc = await AppDbContext.ProductDesc
                                      .Where(m => m.ID.Equals(model.MattressTypeID,
                                                              StringComparison.InvariantCultureIgnoreCase))
                                      .FirstOrDefaultAsync();

            Mattress mattress = new Mattress
            {
                ID           = model.MattressID,
                TypeDesc     = productDesc,
                RegisterDate = model.SaleDate,
                SaleDate     = model.SaleDate,
            };

            SaleToCustomerDetail saleToCustomerDetail = new SaleToCustomerDetail
            {
                Gifts           = model.Gifts,
                DeliveryAddress = model.DeliveryAddress,
                Prodect         = mattress,
                Price           = productDesc.Price,
                CashCoupon      = model.IsUseCashCoupon ? 1000 : 0
            };
            SaleToCustomer saleToCustomer = new SaleToCustomer
            {
                ID            = IDGenerator.GetSaleToCustomerIDGenerator(AppDbContext).GetNext(),
                Customer      = this.AppDbContext.FindOrAttachToLocal(model.CustomerID),
                SellingAgents = this.AppDbContext.FindOrAttachToLocal(loginUser.UserName),
                DealDate      = model.SaleDate,
            };

            saleToCustomerDetail.Sale = saleToCustomer;
            saleToCustomer.DetailItems.Add(saleToCustomerDetail);

            // this.AppDbContext.TryToAttach(saleToCustomer.Customer, (l, r) => r.MemberID.Equals(l.MemberID));
            //  this.AppDbContext.TryToAttach(saleToCustomer.SellingAgents, (l, r) => r.MemberID.Equals(l.MemberID));
            //AppDbContext.Members.Attach(saleToCustomer.Customer);
            // AppDbContext.Members.Attach(saleToCustomer.SellingAgents);

            AppDbContext.Mattress.Add(mattress);
            AppDbContext.SaleToCustomer.Add(saleToCustomer);
            AppDbContext.SaleToCustomeDetails.Add(saleToCustomerDetail);

            var pointItems = await AddMemberPoint(saleToCustomerDetail);

            AppDbContext.SaveChanges();

            return(Json(new {
                saleToCustomerID = saleToCustomer.ID,
                memberPointItems = pointItems,
                sellMattressData = new {
                    MattressID = mattress.ID,
                    MattressTypeName = mattress.TypeDesc.DisplayName,
                    DeliveryAddress = saleToCustomerDetail.DeliveryAddress,
                    CustomerID = saleToCustomer.Customer.MemberID,
                    SaleDate = saleToCustomer.DealDate.Date.ToString("yyyy'-'MM'-'dd"),
                    Gifts = saleToCustomerDetail.Gifts,
                    IsUseCashCoupon = model.IsUseCashCoupon
                },
                JsonRequestBehavior.AllowGet
            }));
        }
예제 #4
0
파일: Store.cs 프로젝트: davidbedok/oeprog2
 public void addBed(String fancyName, Room room, Material material, Size size, double price, Mattress mattress, bool doubleSize, bool compactSize,
         bool builtInLamp, int count)
 {
     this.addFurniture(new Bed(fancyName, room, material, size, price, mattress, doubleSize, compactSize, builtInLamp), count);
 }
예제 #5
0
파일: Bed.cs 프로젝트: davidbedok/oeprog2
 public Bed(RoomType roomType, Material baseMaterial, Size size, int numberOfUser, Mattress mattress)
     : base(roomType, baseMaterial,size)
 {
     this.numberOfUser = numberOfUser;
     this.mattress = mattress;
 }