Beispiel #1
0
        public AddressModel GetAddress(long id)             //return address by address ID
        {
            var entity = _addressDA.GetAddress(id);
            var model  = _mapper.Map <Address, AddressModel>(entity);

            return(model);
        }
Beispiel #2
0
        public Boolean PlaceOrder(PlacedOrderModel model)
        {
            var orders = new List <PlacedOrder>();
            var modelK = _kartDA.GetCustomerKart(model.Customer_ID);

            var orderNumber = _placeOrderDA.GetOrderNumber();     //Creating Order number

            if (orderNumber == 0)
            {
                orderNumber = 999;
            }
            orderNumber += 1;

            var    modelA  = _addressDA.GetAddress(model.Address_ID);  //Creating Address
            string address = "Address Line : " + modelA.AddressLine + " City : " + modelA.City + " State : " + modelA.State +
                             " Postal Code : " + modelA.PostalCode + " Address Type : " + modelA.AddressType;

            foreach (var k in modelK)
            {
                if (k.Quantity == 0)
                {
                    continue;
                }

                //common start
                var order = new PlacedOrder();
                order.Customer_ID = model.Customer_ID;
                order.PaymentType = model.PaymentType;

                order.Address  = address;
                order.DateTime = DateTime.Now;
                order.Status   = "Order Placed";

                order.OrderNumber = orderNumber;
                //common finish


                var product = _productDA.GetProduct(k.Product_ID);
                order.Quantity = k.Quantity;
                var ActualPrice = product.ProductPrice - (product.ProductPrice * product.ProductDiscount) / 100;

                order.Amount     = k.Quantity * ActualPrice;
                order.Product_ID = k.Product_ID;
                product.ProductQuantityInKart -= k.Quantity;            //releasing product IN kart value
                product.ProductQuantity       -= k.Quantity;            //Normelizing Quantity
                _kartDA.RemoveKartItem(k.ID, product);                  //remove from kart and updating product IN Kart value
                orders.Add(order);
            }
            if (_placeOrderDA.PlaceOrder(orders))
            {
                return(true);
            }
            return(false);
        }