Exemplo n.º 1
0
            public IActionResult PersonalAccount(PersonalAccountVM accountVM)
            {
                Customer c            = accountVM.customer;
                string   first_name   = accountVM.first_name;
                string   last_name    = accountVM.last_name;
                string   new_password = accountVM.new_password;

                int date;
                int month;

                switch (accountVM.month)
                {
                case "January":
                    month = 1;
                    break;

                case "Febuary":
                    month = 2;
                    break;

                case "March":
                    month = 3;
                    break;

                case "April":
                    month = 4;
                    break;

                case "May":
                    month = 5;
                    break;

                case "June":
                    month = 6;
                    break;

                case "July":
                    month = 7;
                    break;

                case "August":
                    month = 8;
                    break;

                case "September":
                    month = 9;
                    break;

                case "October":
                    month = 10;
                    break;

                case "November":
                    month = 11;
                    break;

                case "December":
                default:
                    month = 12;
                    break;
                }
                switch (month)
                {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    date = accountVM.date;
                    break;

                case 4:
                case 6:
                case 9:
                case 11:
                    if (accountVM.date > 30)
                    {
                        date = 30;
                    }
                    else
                    {
                        date = accountVM.date;
                    }
                    break;

                case 2:
                default:
                    if (accountVM.date > 28)
                    {
                        date = 28;
                    }
                    else
                    {
                        date = accountVM.date;
                    }
                    break;
                }
                int    year   = accountVM.year;
                string gender = accountVM.gender;

                if (ModelState.IsValid)
                {
                    if (accountVM.customer != null)
                    {
                        if (account.customer.id == 0)
                        {
                            Customer customer = new Customer();
                            customer.fullName = first_name + "_" + last_name;
                            customer.email    = c.email;
                            customer.gender   = gender == "Male" ? true : false;
                            customer.password = new_password;
                            DateTime birth = new DateTime(year, month, date);
                            customer.birth    = birth;
                            customer.created  = DateTime.Now;
                            customer.closed   = DateTime.Now;
                            customer.username = accountVM.customer.username;
                            db.Customer.Add(customer);
                            db.SaveChanges();
                        }
                        else
                        {
                            Customer customer = db.Customer.Where(_c => _c.id == account.customer.id).FirstOrDefault();
                            customer.fullName = first_name + "_" + last_name;
                            customer.email    = c.email;
                            customer.gender   = gender == "Male" ? true : false;
                            if (new_password != "" || new_password != null)
                            {
                                customer.password = new_password;
                            }
                            DateTime birth = new DateTime(year, month, date);
                            customer.birth    = birth;
                            customer.created  = DateTime.Now;
                            customer.closed   = DateTime.Now;
                            customer.username = accountVM.customer.username;
                            Customer cus = db.Customer.FirstOrDefault();
                            db.Entry(cus).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                            db.SaveChanges();

                            db.Customer.Update(customer);
                            db.SaveChanges();
                        }
                    }
                }
                account.new_password = "";
                return(View(account));
            }
Exemplo n.º 2
0
        public UserController(ShopDatabaseContext context)
        {
            this.db      = context;
            products     = db.Product.ToList();
            productSizes = db.ProductSize.ToList();
            images       = db.Image.ToList();
            if (category_filters == null || category_filters.Count() == 0)
            {
                category_filters = new List <string>();
            }
            if (size_filters == null || size_filters.Count() == 0)
            {
                size_filters = new List <string>();
            }
            if (price_filters == null || price_filters.Count() == 0)
            {
                price_filters = new List <int>();
            }

            if (cart_products == null || cart_products.Count() == 0)
            {
                cart_products = new List <Product>();
            }
            if (cart_items == null || cart_items.Count == 0)
            {
                cart_items = new List <ItemForm>();
            }
            if (wish_products == null || wish_products.Count() == 0)
            {
                wish_products = new List <Product>();
            }
            if (detail_products == null || detail_products.Count() == 0)
            {
                detail_products = new List <Product>();
            }
            if (cart_images == null || cart_images.Count() == 0)
            {
                cart_images = new List <Image>();
            }
            if (wish_images == null || wish_images.Count() == 0)
            {
                wish_images = new List <Image>();
            }
            if (detail_images == null || detail_images.Count() == 0)
            {
                detail_images = new List <Image>();
            }
            if (customer == null)
            {
                account = new PersonalAccountVM()
                {
                    customer = new Customer()
                    {
                        id       = 0,
                        username = ""
                    },
                    first_name = "",
                    last_name  = "",
                    date       = 1,
                    id         = 0
                };

                address = new PersonalAddressVM()
                {
                    addresses      = new List <Address>(),
                    company_name   = "",
                    country        = "",
                    address_line_1 = "",
                    address_line_2 = "",
                    city           = "",
                    ZIPcode        = "",
                    mobile_phone   = "",
                };
            }
            else
            {
                account = new PersonalAccountVM()
                {
                    customer   = customer,
                    first_name = customer.fullName.Split('_')[0],
                    last_name  = customer.fullName.Split('_')[1],
                    id         = customer.id
                };
                address = new PersonalAddressVM()
                {
                    addresses      = db.Address.Where(a => a.customer == customer.id).ToList(),
                    company_name   = "",
                    country        = "",
                    address_line_1 = "",
                    address_line_2 = "",
                    city           = "",
                    ZIPcode        = "",
                    mobile_phone   = "",
                };
            }
            if (customer != null && customer.id != 0)
            {
                checkOut             = new CheckOutVM();
                checkOut.last_name   = customer.fullName.Split('_')[1];
                checkOut.first_name  = customer.fullName.Split('_')[0];
                checkOut.email       = customer.email;
                checkOut.order_items = new List <Product>();
                checkOut.itemForms   = new List <ItemForm>();

                List <Address> adds = db.Address.Where(a => a.customer == customer.id).ToList();
                if (adds.Count != 0)
                {
                    Address defa = adds.Where(a => a.isDefaultAddress == true).FirstOrDefault();
                    if (defa == null)
                    {
                        defa = adds[0];
                    }
                    checkOut.company_name   = defa.detail.Split('_')[0];
                    checkOut.address_line_1 = defa.detail.Split('_')[1];
                    checkOut.address_line_2 = defa.detail.Split('_')[2];
                    checkOut.city           = defa.detail.Split('_')[3];
                    checkOut.country        = defa.detail.Split('_')[4];
                    checkOut.mobile_phone   = defa.phone;
                }
            }
            else
            {
                checkOut             = new CheckOutVM();
                checkOut.order_items = new List <Product>();
                checkOut.itemForms   = new List <ItemForm>();
            }
            if (customer == null)
            {
                customer = new Customer()
                {
                    fullName = "_",
                    id       = 0,
                };
            }
            if (login == null)
            {
                login = new LoginVM()
                {
                    username   = "",
                    password   = "",
                    isLoggedIn = false,
                };
            }
            if (catalog == null)
            {
                catalog       = new CatalogProductVM();
                catalog.items = new List <ItemForm>();
            }
            initCatalog(products, productSizes, images);
        }