Esempio n. 1
0
        public async Task <ActionResult> deleteShipping(string id)
        {
            var _defaultId = "";
            var userId     = User.Identity.GetUserId();

            CustomerShippingAddress customerShippingAddress = await data.CustomerShippingAddresses.FindAsync(id);

            var _NoDefaultAddress = await data.CustomerShippingAddresses.Where(i => i.AspNetUserId == userId && i.Id != id).ToListAsync();


            if (customerShippingAddress.IsDefault)
            {
                if (_NoDefaultAddress.Count >= 1)
                {
                    _defaultId = _NoDefaultAddress.Last().Id;
                    _NoDefaultAddress.Last().IsDefault = true;
                }
                else
                {
                    _defaultId = "0";
                }
            }
            else
            {
                _defaultId = _NoDefaultAddress.Where(i => i.IsDefault == true).Single().Id;
            }

            data.CustomerShippingAddresses.Remove(customerShippingAddress);

            await data.SaveChangesAsync();

            return(Json(_defaultId, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            CustomerShippingAddress customerShippingAddress = await db.CustomerShippingAddresses.FindAsync(id);

            db.CustomerShippingAddresses.Remove(customerShippingAddress);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,AspNetUserId,IsDefault,Line1,Line2,City,State")] CustomerShippingAddress customerShippingAddress)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customerShippingAddress).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.AspNetUserId = new SelectList(db.AspNetUsers, "Id", "Email", customerShippingAddress.AspNetUserId);
            return(View(customerShippingAddress));
        }
Esempio n. 4
0
        public async Task <JsonResult> editShipping(CustomerShippingAddress customerShippingAddress)
        {
            if (ModelState.IsValid)
            {
                data.Entry(customerShippingAddress).State = EntityState.Modified;
                await data.SaveChangesAsync();

                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
        // GET: CustomerShippingAddresses/Details/5
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerShippingAddress customerShippingAddress = await db.CustomerShippingAddresses.FindAsync(id);

            if (customerShippingAddress == null)
            {
                return(HttpNotFound());
            }
            return(View(customerShippingAddress));
        }
        // GET: CustomerShippingAddresses/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerShippingAddress customerShippingAddress = await db.CustomerShippingAddresses.FindAsync(id);

            if (customerShippingAddress == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AspNetUserId = new SelectList(db.AspNetUsers, "Id", "Email", customerShippingAddress.AspNetUserId);
            return(View(customerShippingAddress));
        }
        public async Task <ActionResult> Create([Bind(Include = "IsDefault,Line1,Line2,City,State")] CustomerShippingAddress customerShippingAddress)
        {
            var userId = User.Identity.GetUserId();

            customerShippingAddress.AspNetUserId = userId;
            customerShippingAddress.Id           = Guid.NewGuid().ToString();

            if (ModelState.IsValid)
            {
                db.CustomerShippingAddresses.Add(customerShippingAddress);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(customerShippingAddress));
        }
Esempio n. 8
0
        public async Task <JsonResult> createShipping(CustomerShippingAddress customerShippingAddress)
        {
            var userId = User.Identity.GetUserId();

            customerShippingAddress.AspNetUserId = userId;
            customerShippingAddress.Id           = Guid.NewGuid().ToString();

            if (ModelState.IsValid)
            {
                data.CustomerShippingAddresses.Add(customerShippingAddress);
                await data.SaveChangesAsync();

                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Esempio n. 9
0
        internal static void Add(Container container)
        {
            var category1 = new Category()
            {
                Id       = -1,
                Name     = "clothes",
                ParentId = null
            };
            var category2 = new Category()
            {
                Id       = -2,
                Name     = "unknown",
                ParentId = null
            };
            var category3 = new Category()
            {
                Id       = -3,
                Name     = "hats",
                ParentId = -1
            };
            var category4 = new Category()
            {
                Id       = -4,
                Name     = "jackets",
                ParentId = -1
            };
            var category5 = new Category()
            {
                Id       = -5,
                Name     = "baseball cap",
                ParentId = -3
            };
            var category6 = new Category()
            {
                Id       = -6,
                Name     = "sombrero",
                ParentId = -3
            };
            var category7 = new Category()
            {
                Id       = -7,
                Name     = "fur coat",
                ParentId = -4
            };
            var category8 = new Category()
            {
                Id       = -8,
                Name     = "cloak",
                ParentId = -4
            };

            var customer1 = new Customer()
            {
                Address = "Moscow",
                Country = "RU",
                Id      = 1,
                Name    = "Ivan",
                Sex     = Sex.Male
            };
            var customer2 = new Customer()
            {
                Address = "London",
                Country = "EN",
                Id      = 1,
                Name    = "Natasha",
                Sex     = Sex.Female
            };
            var customer3 = new Customer()
            {
                Address = "Tula",
                Country = "RU",
                Id      = 2,
                Name    = "Sasha",
                Sex     = Sex.Female
            };
            var customer4 = new Customer()
            {
                Address = null,
                Country = "UN",
                Id      = 1,
                Name    = "Unknown",
                Sex     = null
            };

            var order1 = new Order()
            {
                AltCustomerCountry = null,
                AltCustomerId      = null,
                Date            = DateTimeOffset.Parse("2016-07-04T19:10:10.8237573+03:00"),
                Id              = -1,
                Name            = "Order 1",
                CustomerCountry = "RU",
                CustomerId      = 1,
                Status          = OrderStatus.Processing
            };
            var order2 = new Order()
            {
                AltCustomerCountry = null,
                AltCustomerId      = null,
                Date            = DateTimeOffset.Parse("2016-07-04T19:10:11.0000000+03:00"),
                Id              = -2,
                Name            = "Order 2",
                CustomerCountry = "EN",
                CustomerId      = 1,
                Status          = OrderStatus.Processing
            };
            var order3 = new Order()
            {
                AltCustomerCountry = "RU",
                AltCustomerId      = 2,
                Date            = null,
                Id              = -3,
                Name            = "Order unknown",
                CustomerCountry = "UN",
                CustomerId      = 1,
                Status          = OrderStatus.Unknown
            };
            var order4 = new Order()
            {
                AltCustomerCountry = "RU",
                AltCustomerId      = 2,
                Date            = DateTimeOffset.Parse("2020-02-20T20:20:20.0000020+03:00"),
                Id              = -4,
                Name            = "Order Ivan",
                CustomerCountry = "RU",
                CustomerId      = 1,
                Status          = OrderStatus.Cancelled
            };

            var orderItem11 = new OrderItem()
            {
                Count   = 1,
                Id      = -1,
                OrderId = -1,
                Price   = 1.1m,
                Product = "Product order 1 item 1"
            };
            var orderItem12 = new OrderItem()
            {
                Count   = 2,
                Id      = -2,
                OrderId = -1,
                Price   = 1.2m,
                Product = "Product order 1 item 2"
            };
            var orderItem13 = new OrderItem()
            {
                Count   = 3,
                Id      = -3,
                OrderId = -1,
                Price   = 1.3m,
                Product = "Product order 1 item 3"
            };

            var orderItem21 = new OrderItem()
            {
                Count   = 1,
                Id      = -4,
                OrderId = -2,
                Price   = 2.1m,
                Product = "Product order 2 item 1"
            };
            var orderItem22 = new OrderItem()
            {
                Count   = 2,
                Id      = -5,
                OrderId = -2,
                Price   = 2.2m,
                Product = "Product order 2 item 2"
            };
            var orderItem31 = new OrderItem()
            {
                Count   = null,
                Id      = -6,
                OrderId = -3,
                Price   = null,
                Product = "Product order 3 item 1 (unknown)"
            };
            var orderItem32 = new OrderItem()
            {
                Count   = 0,
                Id      = -7,
                OrderId = -3,
                Price   = 0,
                Product = "{ null }.Sum() == 0"
            };

            var shippingAddress11 = new ShippingAddress()
            {
                Address = "Moscow 1",
                Id      = 1,
                OrderId = -1
            };
            var shippingAddress12 = new ShippingAddress()
            {
                Address = "Moscow 2",
                Id      = 2,
                OrderId = -1
            };
            var shippingAddress21 = new ShippingAddress()
            {
                Address = "London 1",
                Id      = 1,
                OrderId = -2
            };
            var shippingAddress22 = new ShippingAddress()
            {
                Address = "London 2",
                Id      = 2,
                OrderId = -2
            };
            var shippingAddress23 = new ShippingAddress()
            {
                Address = "London 3",
                Id      = 3,
                OrderId = -2
            };

            var customerShippingAddress1 = new CustomerShippingAddress()
            {
                CustomerCountry        = "EN",
                CustomerId             = 1,
                ShippingAddressOrderId = -2,
                ShippingAddressId      = 1
            };
            var customerShippingAddress2 = new CustomerShippingAddress()
            {
                CustomerCountry        = "EN",
                CustomerId             = 1,
                ShippingAddressOrderId = -2,
                ShippingAddressId      = 2
            };
            var customerShippingAddress3 = new CustomerShippingAddress()
            {
                CustomerCountry        = "EN",
                CustomerId             = 1,
                ShippingAddressOrderId = -2,
                ShippingAddressId      = 3
            };
            var customerShippingAddress4 = new CustomerShippingAddress()
            {
                CustomerCountry        = "RU",
                CustomerId             = 1,
                ShippingAddressOrderId = -1,
                ShippingAddressId      = 1
            };
            var customerShippingAddress5 = new CustomerShippingAddress()
            {
                CustomerCountry        = "RU",
                CustomerId             = 1,
                ShippingAddressOrderId = -1,
                ShippingAddressId      = 2
            };

            var manyColumns1 = new ManyColumns()
            {
                Column01 = 1,
                Column02 = 2,
                Column03 = 3,
                Column04 = 4,
                Column05 = 5,
                Column06 = 6,
                Column07 = 7,
                Column08 = 8,
                Column09 = 9,
                Column10 = 10,
                Column11 = 11,
                Column12 = 12,
                Column13 = 13,
                Column14 = 14,
                Column15 = 15,
                Column16 = 16,
                Column17 = 17,
                Column18 = 18,
                Column19 = 19,
                Column20 = 20,
                Column21 = 21,
                Column22 = 22,
                Column23 = 23,
                Column24 = 24,
                Column25 = 25,
                Column26 = 26,
                Column27 = 27,
                Column28 = 28,
                Column29 = 29,
                Column30 = 30
            };
            var manyColumns2 = new ManyColumns()
            {
                Column01 = 101,
                Column02 = 102,
                Column03 = 103,
                Column04 = 104,
                Column05 = 105,
                Column06 = 106,
                Column07 = 107,
                Column08 = 108,
                Column09 = 109,
                Column10 = 110,
                Column11 = 111,
                Column12 = 112,
                Column13 = 113,
                Column14 = 114,
                Column15 = 115,
                Column16 = 116,
                Column17 = 117,
                Column18 = 118,
                Column19 = 119,
                Column20 = 120,
                Column21 = 121,
                Column22 = 122,
                Column23 = 123,
                Column24 = 124,
                Column25 = 125,
                Column26 = 126,
                Column27 = 127,
                Column28 = 128,
                Column29 = 129,
                Column30 = 130
            };

            container.AddToCategories(category1);
            container.AddToCategories(category2);
            container.AddToCategories(category3);
            container.AddToCategories(category4);
            container.AddToCategories(category5);
            container.AddToCategories(category6);
            container.AddToCategories(category7);
            container.AddToCategories(category8);

            container.AddToCustomers(customer1);
            container.AddToCustomers(customer2);
            container.AddToCustomers(customer3);
            container.AddToCustomers(customer4);

            container.AddToOrders(order1);
            container.AddToOrders(order2);
            container.AddToOrders(order3);
            container.AddToOrders(order4);

            container.AddToOrderItems(orderItem11);
            container.AddToOrderItems(orderItem12);
            container.AddToOrderItems(orderItem13);
            container.AddToOrderItems(orderItem21);
            container.AddToOrderItems(orderItem22);
            container.AddToOrderItems(orderItem31);
            container.AddToOrderItems(orderItem32);

            container.AddToShippingAddresses(shippingAddress11);
            container.AddToShippingAddresses(shippingAddress12);
            container.AddToShippingAddresses(shippingAddress21);
            container.AddToShippingAddresses(shippingAddress22);
            container.AddToShippingAddresses(shippingAddress23);

            container.AddToCustomerShippingAddress(customerShippingAddress1);
            container.AddToCustomerShippingAddress(customerShippingAddress2);
            container.AddToCustomerShippingAddress(customerShippingAddress3);
            container.AddToCustomerShippingAddress(customerShippingAddress4);
            container.AddToCustomerShippingAddress(customerShippingAddress5);

            container.AddToManyColumns(manyColumns1);
            container.AddToManyColumns(manyColumns2);
        }
Esempio n. 10
0
        private static void Delete(Container container)
        {
            var category4 = new Category()
            {
                Id = 4
            };

            container.AttachTo("Categories", category4);
            container.DeleteObject(category4);

            var category7 = new Category()
            {
                Id = 7
            };

            container.AttachTo("Categories", category7);
            container.DeleteObject(category7);

            var category8 = new Category()
            {
                Id = 8
            };

            container.AttachTo("Categories", category8);
            container.DeleteObject(category8);

            var customerShippingAddress1 = new CustomerShippingAddress()
            {
                CustomerCountry = "EN", CustomerId = 1, ShippingAddressOrderId = 2, ShippingAddressId = 1
            };

            container.AttachTo("CustomerShippingAddress", customerShippingAddress1);
            container.DeleteObject(customerShippingAddress1);

            var customerShippingAddress2 = new CustomerShippingAddress()
            {
                CustomerCountry = "EN", CustomerId = 1, ShippingAddressOrderId = 2, ShippingAddressId = 2
            };

            container.AttachTo("CustomerShippingAddress", customerShippingAddress2);
            container.DeleteObject(customerShippingAddress2);

            var customerShippingAddress3 = new CustomerShippingAddress()
            {
                CustomerCountry = "EN", CustomerId = 1, ShippingAddressOrderId = 2, ShippingAddressId = 3
            };

            container.AttachTo("CustomerShippingAddress", customerShippingAddress3);
            container.DeleteObject(customerShippingAddress3);

            var orderItem1 = new OrderItem()
            {
                Id = 1
            };

            container.AttachTo("OrderItems", orderItem1);
            container.DeleteObject(orderItem1);

            var orderItem2 = new OrderItem()
            {
                Id = 2
            };

            container.AttachTo("OrderItems", orderItem2);
            container.DeleteObject(orderItem2);

            var orderItem4 = new OrderItem()
            {
                Id = 4
            };

            container.AttachTo("OrderItems", orderItem4);
            container.DeleteObject(orderItem4);

            var orderItem5 = new OrderItem()
            {
                Id = 5
            };

            container.AttachTo("OrderItems", orderItem5);
            container.DeleteObject(orderItem5);

            var shippingAddress21 = new ShippingAddress()
            {
                OrderId = 2, Id = 1
            };

            container.AttachTo("ShippingAddresses", shippingAddress21);
            container.DeleteObject(shippingAddress21);

            var shippingAddress22 = new ShippingAddress()
            {
                OrderId = 2, Id = 2
            };

            container.AttachTo("ShippingAddresses", shippingAddress22);
            container.DeleteObject(shippingAddress22);

            var shippingAddress23 = new ShippingAddress()
            {
                OrderId = 2, Id = 3
            };

            container.AttachTo("ShippingAddresses", shippingAddress23);
            container.DeleteObject(shippingAddress23);

            var order2 = new Order()
            {
                Id = 2
            };

            container.AttachTo("Orders", order2);
            container.DeleteObject(order2);
        }
Esempio n. 11
0
        public async Task <ActionResult> PaymentMethod(CheckOutModels model)
        {
            var userId = User.Identity.GetUserId();


            //update shipping address if has changes and add if new
            if (model.ShippingAddress.Id == null)
            {
                var _newAddress = new CustomerShippingAddress()
                {
                    Id           = Guid.NewGuid().ToString(),
                    AspNetUserId = userId,
                    City         = model.ShippingAddress.City,
                    IsDefault    = model.ShippingAddress.IsDefault,
                    Line1        = model.ShippingAddress.Line1,
                    Line2        = model.ShippingAddress.Line2,
                    State        = model.ShippingAddress.State
                };

                //unselect all except this
                if (model.ShippingAddress.IsDefault)
                {
                    var _defaults = await data.CustomerShippingAddresses.Where(i => i.AspNetUserId == userId).ToListAsync();

                    foreach (var o in _defaults)
                    {
                        if (o.Id != model.ShippingAddress.Id)
                        {
                            o.IsDefault = false;
                        }
                    }
                }



                data.CustomerShippingAddresses.Add(_newAddress);
                await data.SaveChangesAsync();
            }
            else
            {
                bool hasChanges     = false;
                bool defaultChanges = false;

                var _address = await data.CustomerShippingAddresses.FindAsync(model.ShippingAddress.Id);


                //if address changes
                if (_address.IsDefault != model.ShippingAddress.IsDefault)
                {
                    _address.IsDefault = model.ShippingAddress.IsDefault;
                    hasChanges         = true;
                    defaultChanges     = true;
                }
                if (_address.Line1 != model.ShippingAddress.Line1)
                {
                    _address.Line1 = model.ShippingAddress.Line1;
                    hasChanges     = true;
                }
                if (_address.Line2 != model.ShippingAddress.Line2)
                {
                    _address.Line2 = model.ShippingAddress.Line2;
                    hasChanges     = true;
                }
                if (_address.City != model.ShippingAddress.City)
                {
                    _address.City = model.ShippingAddress.City;
                    hasChanges    = true;
                }
                if (_address.State != model.ShippingAddress.State)
                {
                    _address.State = model.ShippingAddress.State;
                    hasChanges     = true;
                }

                //unselect all except this
                if (defaultChanges)
                {
                    var _defaults = await data.CustomerShippingAddresses.Where(i => i.AspNetUserId == userId).ToListAsync();

                    foreach (var o in _defaults)
                    {
                        if (o.Id != model.ShippingAddress.Id)
                        {
                            o.IsDefault = false;
                        }
                    }
                }

                if (hasChanges)
                {
                    await data.SaveChangesAsync();
                }
            }


            var _model = new CheckOutModels()
            {
                Cart = await dataLayer.getProductsListFromCart(userId, true),
            };

            return(View(_model));
        }