예제 #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);
            }
        }
        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);
            }
        }
예제 #6
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);
            }
        }
        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);
            }
        }
예제 #8
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);
            }
        }
예제 #9
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);
            }
        }
예제 #10
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);
            }
        }