コード例 #1
0
        public CustomerModel UpdateModel(int id, CustomerModel cm)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var user_profile = context.tbl_Customer.FirstOrDefault(x => x.CustomerID == id);

                user_profile.Email     = cm.Email;
                user_profile.FirstName = cm.FirstName;
                user_profile.LastName  = cm.LastName;
                user_profile.Phone     = cm.Phone;
                user_profile.Password  = cm.Password;

                context.SaveChanges();

                CustomerModel customerModel = new CustomerModel()
                {
                    FirstName = user_profile.FirstName,
                    LastName  = user_profile.LastName,
                    Phone     = user_profile.Phone,
                    Email     = user_profile.Email,
                    Password  = user_profile.Password
                };

                return(customerModel);
            }
        }
コード例 #2
0
 public void DeleteContact(int id)
 {
     using (var context = new MobileBazaarDBEntities())
     {
         var p = context.tbl_Contact.FirstOrDefault(x => x.ContactID == id);
         context.tbl_Contact.Remove(p);
         context.SaveChanges();
     }
 }
コード例 #3
0
 public void EditProductQuantity(int pId, int quantity)
 {
     using (var context = new MobileBazaarDBEntities())
     {
         var product = context.tbl_Product.FirstOrDefault(x => x.ProductID == pId);
         product.SoldItems += quantity;
         context.SaveChanges();
     }
 }
コード例 #4
0
        public int AddProduct(ProductModel model)
        {
            string fileName  = Path.GetFileNameWithoutExtension(model.ImageFile.FileName);
            string extension = Path.GetExtension(model.ImageFile.FileName);

            fileName        = fileName + DateTime.Now.ToString("yymmssff") + extension;
            model.ImagePath = "~/Product_Images/" + fileName;

            fileName = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Product_Images/"), fileName);

            model.ImageFile.SaveAs(fileName);

            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Product pd = new tbl_Product()
                {
                    ProductName       = model.ProductName,
                    Brand             = model.Brand,
                    Warranty          = model.Warranty,
                    Quantity          = model.Quantity,
                    SoldItems         = 0,
                    Price             = model.Price,
                    ImagePath         = model.ImagePath,
                    DisplayType       = model.DisplayType,
                    DisplaySize       = model.DisplaySize,
                    Resolution        = model.Resolution,
                    SelfieCamera      = model.SelfieCamera,
                    MainCamera        = model.MainCamera,
                    OperatingSystem   = model.OperatingSystem,
                    Chipset           = model.Chipset,
                    CPU               = model.CPU,
                    GPU               = model.GPU,
                    ROM               = model.ROM,
                    RAM               = model.RAM,
                    Weight            = model.Weight,
                    Color             = model.Color,
                    Dimension         = model.Dimension,
                    WLAN              = model.WLAN,
                    Bluetooth         = model.Bluetooth,
                    GPS               = model.GPS,
                    USB               = model.USB,
                    BatteryType       = model.BatteryType,
                    Sensors           = model.Sensors,
                    Video             = model.Video,
                    NetworkTechnology = model.NetworkTechnology,
                    SIM               = model.SIM,
                    ReleaseYear       = model.ReleaseYear
                };

                context.tbl_Product.Add(pd);
                context.SaveChanges();

                return(pd.ProductID);
            }
        }
コード例 #5
0
        public List <ContactModel> GetAllContacts()
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var list = context.tbl_Contact.
                           Select(x => new ContactModel()
                {
                    ContactID = x.ContactID,
                    Email     = x.Email,
                    Message   = x.Message
                }).ToList();

                return(list);
            }
        }
コード例 #6
0
        public int CheckAuthenticity(String email, String password)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Customer customer = context.tbl_Customer.Where(x => x.Email == email && x.Password == password).FirstOrDefault();

                if (customer != null)
                {
                    return(customer.CustomerID);
                }
                else
                {
                    return(0);
                }
            }
        }
コード例 #7
0
        public Boolean DeleteProduct(int id)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var cart = context.tbl_Cart.FirstOrDefault(x => x.CartID == id);

                if (cart != null)
                {
                    context.tbl_Cart.Remove(cart);
                    context.SaveChanges();
                    return(true);
                }

                return(false);
            }
        }
コード例 #8
0
        public Boolean AddContact(String email, String message)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Contact cs = new tbl_Contact()
                {
                    Email   = email,
                    Message = message
                };

                context.tbl_Contact.Add(cs);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #9
0
        public ProductModel GetProduct(int id)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var product = context.tbl_Product.FirstOrDefault(x => x.ProductID == id);

                ProductModel productModel = new ProductModel()
                {
                    ProductID         = product.ProductID,
                    ProductName       = product.ProductName,
                    Brand             = product.Brand,
                    Warranty          = product.Warranty,
                    Quantity          = product.Quantity,
                    SoldItems         = product.SoldItems,
                    Price             = product.Price,
                    ImagePath         = product.ImagePath,
                    DisplayType       = product.DisplayType,
                    DisplaySize       = product.DisplaySize,
                    Resolution        = product.Resolution,
                    SelfieCamera      = product.SelfieCamera,
                    MainCamera        = product.MainCamera,
                    OperatingSystem   = product.OperatingSystem,
                    Chipset           = product.Chipset,
                    CPU               = product.CPU,
                    GPU               = product.GPU,
                    ROM               = product.ROM,
                    RAM               = product.RAM,
                    Weight            = product.Weight,
                    Color             = product.Color,
                    Dimension         = product.Dimension,
                    WLAN              = product.WLAN,
                    Bluetooth         = product.Bluetooth,
                    GPS               = product.GPS,
                    USB               = product.USB,
                    BatteryType       = product.BatteryType,
                    Sensors           = product.Sensors,
                    Video             = product.Video,
                    NetworkTechnology = product.NetworkTechnology,
                    SIM               = product.SIM,
                    ReleaseYear       = product.ReleaseYear
                };

                return(productModel);
            }
        }
コード例 #10
0
        public Boolean AddToCart(CartModel model)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Cart cs = new tbl_Cart()
                {
                    CustomerID = model.CustomerID,
                    ProductID  = model.ProductID,
                    Price      = model.Price,
                    Quantity   = model.Quantity,
                    TotalPrice = model.TotalPrice,
                };

                context.tbl_Cart.Add(cs);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #11
0
        public List <OrderModel> GetAllOrders()
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var l = context.tbl_Order.
                        Select(y => new OrderModel()
                {
                    OrderID     = y.OrderID,
                    CustomerID  = y.CustomerID,
                    ProductID   = y.ProductID,
                    ProductName = y.ProductName,
                    Quantity    = y.Quantity,
                    TotalPrice  = y.TotalPrice,
                    OrderDate   = y.OrderDate
                }).ToList();

                return(l);
            }
        }
コード例 #12
0
        public int AddEmployee(CustomerModel model)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Customer cs = new tbl_Customer()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Phone     = model.Phone,
                    Email     = model.Email,
                    Password  = model.Password
                };

                context.tbl_Customer.Add(cs);
                context.SaveChanges();

                return(cs.CustomerID);
            }
        }
コード例 #13
0
        public CustomerModel GetCustomer(int id)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Customer customer = context.tbl_Customer.Where(x => x.CustomerID == id).FirstOrDefault();

                CustomerModel cm = new CustomerModel()
                {
                    CustomerID = customer.CustomerID,
                    FirstName  = customer.FirstName,
                    LastName   = customer.LastName,
                    Email      = customer.Email,
                    Phone      = customer.Phone,
                    Password   = customer.Password
                };

                return(cm);
            }
        }
コード例 #14
0
        public List <ProductModel> GetAllProducts()
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var list = context.tbl_Product.
                           Select(x => new ProductModel()
                {
                    ProductID         = x.ProductID,
                    ProductName       = x.ProductName,
                    Brand             = x.Brand,
                    Warranty          = x.Warranty,
                    Quantity          = x.Quantity,
                    SoldItems         = x.SoldItems,
                    Price             = x.Price,
                    ImagePath         = x.ImagePath,
                    DisplayType       = x.DisplayType,
                    DisplaySize       = x.DisplaySize,
                    Resolution        = x.Resolution,
                    SelfieCamera      = x.SelfieCamera,
                    MainCamera        = x.MainCamera,
                    OperatingSystem   = x.OperatingSystem,
                    Chipset           = x.Chipset,
                    CPU               = x.CPU,
                    GPU               = x.GPU,
                    ROM               = x.ROM,
                    RAM               = x.RAM,
                    Weight            = x.Weight,
                    Color             = x.Color,
                    Dimension         = x.Dimension,
                    WLAN              = x.WLAN,
                    Bluetooth         = x.Bluetooth,
                    GPS               = x.GPS,
                    USB               = x.USB,
                    BatteryType       = x.BatteryType,
                    Sensors           = x.Sensors,
                    Video             = x.Video,
                    NetworkTechnology = x.NetworkTechnology
                }).ToList();

                return(list);
            }
        }
コード例 #15
0
        public Boolean AddOrder(OrderModel model)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                tbl_Order od = new tbl_Order()
                {
                    CustomerID  = model.CustomerID,
                    ProductID   = model.ProductID,
                    ProductName = model.ProductName,
                    Quantity    = model.Quantity,
                    TotalPrice  = model.TotalPrice,
                    OrderDate   = DateTime.Now.ToString()
                };

                context.tbl_Order.Add(od);
                context.SaveChanges();

                return(true);
            }
        }
コード例 #16
0
        public CartModel GetCart(int id)
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var       item      = context.tbl_Cart.FirstOrDefault(x => x.CartID == id);
                CartModel cartModel = new CartModel()
                {
                    CartID     = item.CartID,
                    CustomerID = item.CustomerID,
                    ProductID  = item.ProductID,
                    Quantity   = item.Quantity,
                    Price      = item.Price,
                    TotalPrice = item.TotalPrice,
                    Product    = new ProductModel()
                    {
                        ProductName = item.tbl_Product.ProductName
                    }
                };

                return(cartModel);
            }
        }
コード例 #17
0
        public List <CartModel> GetAllCarts()
        {
            using (var context = new MobileBazaarDBEntities())
            {
                var list = context.tbl_Cart.
                           Select(x => new CartModel()
                {
                    CartID     = x.CartID,
                    CustomerID = x.CustomerID,
                    ProductID  = x.ProductID,
                    Quantity   = x.Quantity,
                    Price      = x.Price,
                    TotalPrice = x.TotalPrice,
                    Product    = new ProductModel()
                    {
                        ProductName = x.tbl_Product.ProductName
                    }
                }).ToList();

                return(list);
            }
        }
コード例 #18
0
        public Boolean EditProduct(int id, ProductModel productModel)
        {
            String filename  = Path.GetFileNameWithoutExtension(productModel.ImageFile.FileName);
            String extension = Path.GetExtension(productModel.ImageFile.FileName);

            filename = filename + DateTime.Now.ToString("yymmssff") + extension;

            productModel.ImagePath = "~/Product_Images/" + filename;

            filename = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Product_Images/"), filename);

            productModel.ImageFile.SaveAs(filename);

            using (var context = new MobileBazaarDBEntities())
            {
                var product = context.tbl_Product.FirstOrDefault(x => x.ProductID == id);

                product.ProductName       = productModel.ProductName;
                product.Brand             = productModel.Brand;
                product.Warranty          = productModel.Warranty;
                product.Quantity          = productModel.Quantity;
                product.Price             = productModel.Price;
                product.ImagePath         = productModel.ImagePath;
                product.DisplayType       = productModel.DisplayType;
                product.DisplaySize       = productModel.DisplaySize;
                product.Resolution        = productModel.Resolution;
                product.SelfieCamera      = productModel.SelfieCamera;
                product.MainCamera        = productModel.MainCamera;
                product.OperatingSystem   = productModel.OperatingSystem;
                product.Chipset           = productModel.Chipset;
                product.CPU               = productModel.CPU;
                product.GPU               = productModel.GPU;
                product.ROM               = productModel.ROM;
                product.RAM               = productModel.RAM;
                product.Weight            = productModel.Weight;
                product.Color             = productModel.Color;
                product.Dimension         = productModel.Dimension;
                product.WLAN              = productModel.WLAN;
                product.Bluetooth         = productModel.Bluetooth;
                product.GPS               = productModel.GPS;
                product.USB               = productModel.USB;
                product.BatteryType       = productModel.BatteryType;
                product.Sensors           = productModel.Sensors;
                product.Video             = productModel.Video;
                product.NetworkTechnology = productModel.NetworkTechnology;
                product.SIM               = productModel.SIM;
                product.ReleaseYear       = productModel.ReleaseYear;
                product.SoldItems         = 0;
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }

                //context.SaveChanges();

                return(true);
            }
        }