示例#1
0
        public void TestMethod_count_less_zero_should_ArgumentException()
        {
            OrderStatistic <Order> statistic = new OrderStatistic <Order>()
            {
                StatisticCategory = "Cost"
            };

            Action act = () => { statistic.GetSumByGroupCount(-1); };

            act.ShouldThrow <ArgumentException>();
        }
示例#2
0
        private OrderStatistic[] MapOrderStatistic(IReadOnlyList <IEnumerable <Order> > data, IReadOnlyList <string> properties)
        {
            var length = properties.Count;
            var list   = new OrderStatistic[length];

            for (var i = 0; i < length; i++)
            {
                list[i] = new OrderStatistic(properties[i], data[i].ToList().Count, data[i].Sum(x => x.TotalItem), data[i].Sum(x => x.TotalItem));
            }

            return(list);
        }
示例#3
0
        public void GetSumByGroupCount_set_not_exist_category_should_argumentException()
        {
            //  arrange
            OrderStatistic <Order> statistic = new OrderStatistic <Order> {
                StatisticCategory = "Test"
            };

            //  act
            Action act = () => { statistic.GetSumByGroupCount(-1); };

            //  assert
            act.ShouldThrow <ArgumentException>();
        }
示例#4
0
        public void GetSumByGroupCount_input_count_is_0_should_0()
        {
            //  arrange
            OrderStatistic <Order> statistic = new OrderStatistic <Order> {
                StatisticCategory = "Cost"
            };

            List <int> expected = new List <int>()
            {
                0
            };

            //  act
            var actual = statistic.GetSumByGroupCount(0);


            //  assert
            expected.ToExpectedObject().ShouldEqual(actual);
        }
示例#5
0
        public void GetSumByGroupCount_count_3_and_cate_cost_should_4_element()
        {
            //  arrange
            var lst = GetOrders();

            var expected = new List <int>()
            {
                6, 15, 24, 21
            };

            OrderStatistic <Order> statistic = new OrderStatistic <Order>(lst)
            {
                StatisticCategory = "Cost"
            };

            //  act
            var actual = statistic.GetSumByGroupCount(3);

            //  assert
            expected.ToExpectedObject().ShouldEqual(actual);
        }
示例#6
0
        public void GetSumByGroupCount_count_4_and_cate_Revenue_should_3_element()
        {
            //  arrange
            var lst = GetOrders();

            var expected = new List <int>()
            {
                50, 66, 60
            };

            OrderStatistic <Order> statistic = new OrderStatistic <Order>(lst)
            {
                StatisticCategory = "Revenue"
            };

            //  act
            var actual = statistic.GetSumByGroupCount(4);

            //  assert
            expected.ToExpectedObject().ShouldEqual(actual);
        }
示例#7
0
        public OrderDetail Insert(OrderDetailViewModel model, string CurrentId)
        {
            var data = new OrderDetail();

            data.Order            = _repositoryOrder.Find(model.OrderID);
            data.ProductId        = model.ProductID;
            data.Quantity         = model.Quantity;
            data.Price            = model.Price;
            data.IsGift           = model.IsGift;
            data.ProductName      = model.ProductName;
            data.Serial           = model.Serial;
            data.Delete           = false;
            data.CreatDate        = DateTime.Now;
            data.LastModifiedDate = DateTime.Now;
            data.UserAccount      = _userRepository.Find(CurrentId);
            base.Insert(data);
            db.SaveChanges();
            if (model.OrderStatistics != null)
            {
                foreach (var item in model.OrderStatistics)
                {
                    var r = new OrderStatistic();
                    r.CreatDate            = DateTime.Now;
                    r.LastModifiedDate     = DateTime.Now;
                    r.UserAccount          = _userRepository.Find(CurrentId);
                    r.ProductAttributeId   = item.ProductAttributeId;
                    r.ProductAttributeName = item.ProductAttributeName;
                    r.ProductAttributeNote = item.ProductAttributeNote;
                    r.ProductId            = model.ProductID;
                    r.Serial        = model.Serial;
                    r.OrderId       = model.OrderID;
                    r.OrderDetailId = data.Id;
                    _repositoryOrderStatic.Insert(r);
                    db.SaveChanges();
                }
            }
            return(data);
        }
示例#8
0
        public bool Update(OrderViewModel model, string CurrentId)
        {
            //tìm phiếu order
            var Phieu = _repository.Find(model.ID);

            if (Phieu != null)
            {
                Phieu.Delete = false;
                //xóa dữ liệu trong Detail và Stattic
                var statistic = _orderStatisticService.Queryable().Where(x => x.OrderId == model.ID).ToList();
                if (statistic != null)
                {
                    foreach (var item in statistic)
                    {
                        _repositoryStatistic.Delete(item.Id);
                    }
                }
                //xóa dữ liệu trong  Stattic
                var detail = _orderDetailService.Queryable().Where(x => x.Order.Id == Phieu.Id).ToList();
                if (detail != null)
                {
                    foreach (var item in detail)
                    {
                        _repositoryDetail.Delete(item.Id);
                    }
                }
                //Tạo phiếu mới
                var data = new Order();
                data.Code             = Phieu.Code;
                data.Customer         = _customerService.Find(model.CustomerID);
                data.StatusOrder      = model.StatusOrder;
                data.UserAccount      = _userRepository.Find(CurrentId);
                data.Note             = model.Note;
                data.IsGift           = model.IsGift;
                data.CreatDate        = Phieu.CreatDate;
                data.LastModifiedDate = DateTime.Now;
                data.Appointment      = model.Appointment;
                data.SaleEmployeeName = model.SaleEmployeeName;
                data.SaleEmployeeID   = model.SaleEmployeeID;
                data.TypeOrder        = model.TypeOrder;
                data.Source           = model.Source;
                OrderDetail o;
                if (model.OrderDetails != null)
                {
                    data.OrderDetails = new List <OrderDetail>();
                    foreach (var item in model.OrderDetails)
                    {
                        o = new OrderDetail();
                        o = new OrderDetail()
                        {
                            ProductId        = item.ProductID,
                            ProductName      = item.ProductName,
                            Quantity         = item.Quantity,
                            Price            = item.Price,
                            IsGift           = item.IsGift,
                            Serial           = item.Serial,
                            CreatDate        = Phieu.CreatDate,
                            LastModifiedDate = DateTime.Now,
                            UserAccount      = _userRepository.Find(CurrentId),
                            Delete           = false
                        };
                        data.OrderDetails.Add(o);
                        item.ID = o.Id;
                    }
                }
                data.Total = model.OrderDetails.Sum(x => x.Quantity * x.Price);
                _repository.Insert(data);
                model.ID = data.Id;

                //Thêm data vào bảng OrderStatisticService
                foreach (var item in model.OrderDetails)
                {
                    //nếu sản phẩm có thuộc tính
                    if (item.OrderStatistics.Count != 0)
                    {
                        foreach (var item1 in item.OrderStatistics)
                        {
                            var dataProduct = new OrderStatistic();
                            dataProduct.OrderId              = model.ID;
                            dataProduct.ProductAttributeId   = item1.ID;
                            dataProduct.ProductAttributeName = item1.ProductAttributeName;
                            dataProduct.ProductAttributeNote = item1.ProductAttributeNote;
                            dataProduct.CreatDate            = Phieu.CreatDate;
                            dataProduct.LastModifiedDate     = DateTime.Now;
                            dataProduct.ProductId            = item.ProductID;
                            dataProduct.UserAccount          = _userRepository.Find(CurrentId);
                            dataProduct.OrderDetailId        = item.ID;
                            dataProduct.Serial = item.Serial;
                            _repositoryStatistic.Insert(dataProduct);
                        }
                    }
                    else
                    {
                        var dataProduct = new OrderStatistic();
                        dataProduct.OrderId          = model.ID;
                        dataProduct.CreatDate        = Phieu.CreatDate;
                        dataProduct.LastModifiedDate = DateTime.Now;
                        dataProduct.ProductId        = item.ProductID;
                        dataProduct.UserAccount      = _userRepository.Find(CurrentId);
                        dataProduct.OrderDetailId    = item.ID;
                        dataProduct.Serial           = item.Serial;
                        _repositoryStatistic.Insert(dataProduct);
                    }
                }
                //Xóa phiếu
                _repository.Delete(Phieu.Id);
            }

            return(true);
        }
示例#9
0
        public Order Insert(OrderViewModel model, string CurrentId)
        {
            var    data      = new Order();
            Random generator = new Random();
            var    r         = generator.Next(0, 999999).ToString("D6");
            var    CodeOrder = "PSHCM" + DateTime.Now.ToString("yyyy") + DateTime.Now.ToString("MM") + r;
            var    find      = _repository.Queryable().Where(x => x.Code == CodeOrder).Any();

            do
            {
                r         = generator.Next(0, 999999).ToString("D6");
                CodeOrder = "PSHCM" + DateTime.Now.ToString("yyyy") + DateTime.Now.ToString("MM") + r;
                find      = _repository.Queryable().Where(x => x.Code == CodeOrder).Any();
            } while (find == true);

            data.Code             = CodeOrder;
            data.Customer         = _customerService.Find(model.CustomerID);
            data.StatusOrder      = 0;
            data.UserAccount      = _userRepository.Find(CurrentId);
            data.Note             = model.Note;
            data.IsGift           = model.IsGift;
            data.CreatDate        = DateTime.Now;
            data.LastModifiedDate = DateTime.Now;
            data.Appointment      = model.Appointment;
            if (model.SaleEmployeeID == null)
            {
                data.SaleEmployeeID   = _staff.Queryable().Where(x => x.UserAccount.Id == CurrentId).FirstOrDefault().Id;
                data.SaleEmployeeName = _staff.Queryable().Where(x => x.UserAccount.Id == CurrentId).FirstOrDefault().FullName;
            }
            else
            {
                data.SaleEmployeeName = model.SaleEmployeeName;
                data.SaleEmployeeID   = model.SaleEmployeeID;
            }

            data.TypeOrder = model.TypeOrder;
            data.Source    = model.Source;
            OrderDetail o;

            if (model.OrderDetails != null)
            {
                data.OrderDetails = new List <OrderDetail>();
                foreach (var item in model.OrderDetails)
                {
                    o = new OrderDetail();
                    o = new OrderDetail()
                    {
                        ProductId        = item.ProductID,
                        ProductName      = item.ProductName,
                        Quantity         = item.Quantity,
                        Price            = item.Price,
                        IsGift           = item.IsGift,
                        Serial           = item.Serial,
                        CreatDate        = DateTime.Now,
                        LastModifiedDate = DateTime.Now,
                        UserAccount      = _userRepository.Find(CurrentId),
                        Delete           = false
                    };
                    data.OrderDetails.Add(o);
                    item.ID = o.Id;
                }
            }
            data.Total = model.Total;
            _repository.Insert(data);

            model.ID = data.Id;

            //Thêm data vào bảng OrderStatisticService
            foreach (var item in model.OrderDetails)
            {
                //nếu sản phẩm có thuộc tính
                if (item.OrderStatistics.Count != 0)
                {
                    foreach (var item1 in item.OrderStatistics)
                    {
                        var dataProduct = new OrderStatistic();
                        dataProduct.OrderId              = model.ID;
                        dataProduct.ProductAttributeId   = item1.ProductAttributeId;
                        dataProduct.ProductAttributeName = item1.ProductAttributeName;
                        dataProduct.ProductAttributeNote = item1.ProductAttributeNote;
                        dataProduct.CreatDate            = DateTime.Now;
                        dataProduct.LastModifiedDate     = DateTime.Now;
                        dataProduct.ProductId            = item.ProductID;
                        dataProduct.UserAccount          = _userRepository.Find(CurrentId);
                        dataProduct.OrderDetailId        = item.ID;
                        dataProduct.Serial = item.Serial;
                        _repositoryStatistic.Insert(dataProduct);
                    }
                }
                else
                {
                    var dataProduct = new OrderStatistic();
                    dataProduct.OrderId          = model.ID;
                    dataProduct.CreatDate        = DateTime.Now;
                    dataProduct.LastModifiedDate = DateTime.Now;
                    dataProduct.ProductId        = item.ProductID;
                    dataProduct.UserAccount      = _userRepository.Find(CurrentId);
                    dataProduct.OrderDetailId    = item.ID;
                    dataProduct.Serial           = item.Serial;
                    _repositoryStatistic.Insert(dataProduct);
                }
            }

            return(data);
        }