예제 #1
0
        public ActionResult Edit(int?id, string CategoryName)
        {
            if (CategoryName != null)
            {
                Category selectedCategory = db.Categories.FirstOrDefault(ct => ct.id == id);
                if (selectedCategory != null)
                {
                    Category exist = db.Categories.FirstOrDefault(ct => ct.Name == CategoryName);
                    if (exist == null)
                    {
                        selectedCategory.Name = CategoryName;
                        db.SaveChanges();
                        return(RedirectToAction("Index", new { id = id }));
                    }
                    else
                    {
                        ViewBag.error = "bele categoriya var.";
                    }
                }
                else
                {
                    ViewBag.error = "There is no category with this Id.";
                }
            }
            else
            {
                ViewBag.error = "please fill all the fields";
            }

            return(View());
        }
        public int createTestObject()
        {
            beanBag = new BeanBag {
                name = "testObject", beanBagTypeID = 1
            };
            order = new Order
            {
                Username  = "******",
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                street    = "TestStreet",
                hno       = "TestHno",
                Zip       = "TestZip",
                City      = "TestCity",
                Phone     = "TestPhone",
                Email     = "*****@*****.**",
                Total     = 100,
                OrderDate = DateTime.Now
            };

            db.BeanBags.Add(beanBag);
            db.Orders.Add(order);
            //db.Carts.Add(cart);
            db.SaveChanges();

            return(beanBag.id);
        }
        public ActionResult SaveOrder(string name, String address, Order[] order)
        {
            if (Session["AdminLogin"].ToString() != "")
            {
                string result = "Error! Order Is Not Complete!";
                if (name != null && address != null && order != null)
                {
                    var      cutomerId = Guid.NewGuid();
                    Customer model     = new Customer();
                    model.CustomerId = cutomerId;
                    model.Name       = name;
                    model.Address    = address;
                    model.OrderDate  = DateTime.Now;
                    db.Customers.Add(model);

                    foreach (var item in order)
                    {
                        var   orderId = Guid.NewGuid();
                        Order O       = new Order();
                        O.OrderId     = orderId;
                        O.ProductName = item.ProductName;
                        O.Quantity    = item.Quantity;
                        O.Price       = item.Price;
                        O.Amount      = item.Amount;
                        O.CustomerId  = cutomerId;
                        db.Orders.Add(O);
                    }
                    db.SaveChanges();
                    result = "Success! Order Is Complete!";
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Login", "AdminPanel"));
        }
예제 #4
0
        /// <summary>
        /// Create a new product
        /// </summary>
        // POST api/products
        public HttpResponseMessage Post([FromBody] ProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                if (db.ProductCategory.Find(productViewModel.ProductCategoryId) == null)
                {
                    ModelState.AddModelError("ProductCategoryId", "Not found key");
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }

                Product product = new Product
                {
                    Name              = productViewModel.Name,
                    Description       = productViewModel.Description,
                    Price             = productViewModel.Price,
                    Quantity          = productViewModel.Quantity,
                    ProductCategoryId = productViewModel.ProductCategoryId,
                    ImagePath         = productViewModel.ImageName
                };
                db.Product.Add(product);
                db.SaveChanges();
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
예제 #5
0
        public int createTestObject()
        {
            beanBag = new BeanBag {
                name = "testObject", beanBagTypeID = 1
            };
            db.BeanBags.Add(beanBag);
            db.SaveChanges();

            return(beanBag.id);
        }
예제 #6
0
        public ActionResult Create(BeanBag beanbag)
        {
            if (ModelState.IsValid)
            {
                db.BeanBags.Add(beanbag);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(beanbag));
        }
예제 #7
0
        public ActionResult Create([Bind(Include = "Id,UserName,Password")] AdminUser adminUser)
        {
            if (ModelState.IsValid)
            {
                db.AdminUsers.Add(adminUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(adminUser));
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "CustomerId,Name,Address,OrderDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.CustomerId = Guid.NewGuid();
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
예제 #9
0
        public ActionResult Create(BeanBag beanbag)
        {
            if (ModelState.IsValid)
            {
                db.BeanBags.Add(beanbag);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.beanBagTypeID = new SelectList(db.BeanBagTypes, "id", "name", beanbag.beanBagTypeID);
            return(View(beanbag));
        }
예제 #10
0
        public void DeleteCustomer(int id)
        {
            using (var context = new OnlineShopEntities())
            {
                var customerToDel = context.Customers.First(x => x.Id == id);

                if (customerToDel != null)
                {
                    var ordersToDelete = context.Orders.Where(o => o.CustomerId == customerToDel.Id);

                    foreach (var order in ordersToDelete)
                    {
                        var orderItemsToDelete = context.OrderItems.Where(oi => oi.OrderId == order.Id);

                        foreach (var orderItem in orderItemsToDelete)
                        {
                            context.OrderItems.Remove(orderItem);
                        }

                        context.Orders.Remove(order);
                    }
                    context.Customers.Remove(customerToDel);
                }

                context.SaveChanges();
            }
        }
        public ActionResult SaveOrder(string name, string address, Order[] order)
        {
            string result = "Error! Order is Not Complete";

            if (name != null || address != null || order != null)
            {
                var      customerId = Guid.NewGuid();
                Customer model      = new Customer();
                model.CustomerId = customerId;
                model.Name       = name;
                model.Address    = address;
                model.OrderDate  = DateTime.Now;
                db.Customers.Add(model);
                foreach (var item in order)
                {
                    var   orderId = Guid.NewGuid();
                    Order o       = new Order
                    {
                        OrderId     = orderId,
                        ProductName = item.ProductName,
                        Quantity    = item.Quantity,
                        Price       = item.Price,
                        Amount      = item.Amount,
                        CustomerId  = customerId
                    };
                    db.Orders.Add(o);
                }

                db.SaveChanges();
                result = "Success ! Order is completed";
            }
            return(Json(result));
        }
예제 #12
0
        public ActionResult saveOrder(string name, string address, Order[] order)
        {
            string result = "Error! Order is not complete!!!";

            if (name != null || address != null || order != null)
            {
                var      customerId = Guid.NewGuid();
                Customer model      = new Customer();
                model.CustomerId = customerId;
                model.Name       = name;
                model.Address    = address;
                model.OrderDate  = DateTime.Now;
                db.Customers.Add(model);

                foreach (var item in order)
                {
                    var   orderId = Guid.NewGuid();
                    Order O       = new Order();
                    O.OrderId     = orderId;
                    O.ProductName = item.ProductName;
                    O.Quantity    = item.Quantity;
                    O.Price       = item.Price;
                    O.Amount      = item.Amount;
                    O.CustomerId  = customerId;
                    db.Orders.Add(O);
                }
                db.SaveChanges();
                result = "SUCCESS FOR ORDER ^_^";
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index(MyOrderViewModel model)
        {
            if (model.Id > 0)
            {
                Order or = db.Orders.SingleOrDefault(x => x.Id == model.Id);

                or.Id          = model.Id;
                or.ProductName = model.ProductName;
                or.Quantity    = model.Quantity;
                or.Price       = model.Price;
                or.Amount      = model.Amount;
                db.SaveChanges();
            }

            return(View(model));
        }
        public void DeleteCustomers()
        {
            using (var context = new OnlineShopEntities())
            {
                var customersToDel = context
                                     .Customers
                                     .Where(x => x.Lastname == "Ivanov")
                                     .ToList();


                foreach (var customer in customersToDel)
                {
                    var ordersToDelete = context.Orders.Where(o => o.CustomerId == customer.Id);

                    foreach (var order in ordersToDelete)
                    {
                        var orderItemsToDelete = context.OrderItems.Where(oi => oi.OrderId == order.Id);

                        foreach (var orderItem in orderItemsToDelete)
                        {
                            context.OrderItems.Remove(orderItem);
                        }

                        context.Orders.Remove(order);
                    }

                    context.Customers.Remove(customer);
                }

                context.SaveChanges();
            }
        }
예제 #15
0
        public ActionResult Buy(CheckoutPurchase checkoutPurchase)
        {
            Product product;

            foreach (var item in checkoutPurchase)
            {
                product = db.Product.Find(item.ProductId);
                if (product != null)
                {
                    // update quantities products
                    product.Quantity -= item.Quantity;
                    db.Product.Attach(product);
                    db.Entry(product).Property(p => p.Quantity).IsModified = true;

                    // add new purchase
                    Purchase purchase = new Purchase
                    {
                        ClientId    = User.Identity.GetUserId(),
                        ProductId   = item.ProductId,
                        StorageDate = DateTime.Now
                    };
                    db.Purchase.Add(purchase);
                    db.SaveChanges();
                }
                else
                {
                    return(View(checkoutPurchase));
                }
            }
            checkoutPurchase.Clear();
            return(RedirectToAction("Index", "Products"));
        }
 public static int InsertContent(Content content)
 {
     using (var db = new OnlineShopEntities())
     {
         if (string.IsNullOrEmpty(content.MetaTitle))
         {
             content.MetaTitle = StringHelper.ToUnsignString(content.Name);
         }
         db.Contents.Add(content);
         var result = db.SaveChanges();
         if (!string.IsNullOrEmpty(content.Tags))
         {
             string[] tags = content.Tags.Split('-').ToArray();
             for (int i = 0; i < tags.Length; i++)
             {
                 var tagID      = StringHelper.ToUnsignString(tags[i]);
                 var existedTag = CheckTag(tagID);
                 if (!existedTag)
                 {
                     InsertTag(tagID, tags[i]);
                 }
                 InsertContentTag(content.ID, tagID);
             }
         }
         return(result);
     }
 }
예제 #17
0
        //This function adds the information to a user object and adds it to the DB
        public static void RegisterUser(User user)
        {
            OnlineShopEntities db = new OnlineShopEntities();

            db.Users.Add(user);
            db.SaveChanges();
        }
예제 #18
0
        public ActionResult AddressAndPayment(FormCollection values, string Subject, string Body)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                //Save Order
                db.Orders.Add(order);
                db.SaveChanges();

                //Process the order
                var cart = ShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(order);

                Subject = "Order from user" + order.Username;
                Body    = order.LastName;

                return(RedirectToAction("Complete", new { id = order.OrderId }));
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
예제 #19
0
        public ActionResult Edit(int?id, string Name, string Price, int Category_Id)
        {
            decimal pricedecimal;

            if (Name != string.Empty && Price != null)
            {
                if (decimal.TryParse(Price, out pricedecimal))
                {
                    Product existpro = db.Products.FirstOrDefault(pro => pro.Name == Name);
                    if (existpro == null)
                    {
                        Product selectedpro = db.Products.FirstOrDefault(pro => pro.id == id);
                        if (selectedpro != null)
                        {
                            selectedpro.Name        = Name;
                            selectedpro.Price       = pricedecimal;
                            selectedpro.Category_id = Category_Id;

                            db.SaveChanges();
                            return(RedirectToAction("Index", new { id = id }));
                        }
                        else
                        {
                            ViewBag.error = "There is no product with this Id.";
                        }
                    }
                    else
                    {
                        ViewBag.error = "bele bir product adi var.";
                    }
                }
                else
                {
                    ViewBag.error = "price yalniz reqem ola biler";
                }
            }
            else
            {
                ViewBag.error = "please fill all the fields";
            }
            if (id != null)
            {
                ViewBag.AllCategories = db.Categories.ToList();
                ViewBag.ActiveProduct = db.Products.FirstOrDefault(pro => pro.id == id);
            }
            return(View());
        }
 public static void RemoveAllContentTag(long contentId)
 {
     using (var db = new OnlineShopEntities())
     {
         db.ContentTags.RemoveRange(db.ContentTags.Where(x => x.ContentID == contentId));
         db.SaveChanges();
     }
 }
예제 #21
0
        /// <summary>
        /// Create a new product category
        /// </summary>
        // POST api/productcategories
        public HttpResponseMessage Post([FromBody] ProductCategoryViewModel productCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                ProductCategory productCategory = new ProductCategory
                {
                    Name              = productCategoryViewModel.Name,
                    Description       = productCategoryViewModel.Description,
                    ProductCategoryId = productCategoryViewModel.ProductCategoryId,
                    ImagePath         = productCategoryViewModel.ImageName
                };
                db.ProductCategory.Add(productCategory);
                db.SaveChanges();
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
 public static int InsertCategory(Category category)
 {
     using (var db = new OnlineShopEntities())
     {
         db.Categories.Add(category);
         var result = db.SaveChanges();
         return(result);
     }
 }
예제 #23
0
 public static int InsertOrderDetails(OrderDetail orderDetail)
 {
     using (var db = new OnlineShopEntities())
     {
         db.OrderDetails.Add(orderDetail);
         var result = db.SaveChanges();
         return(result);
     }
 }
예제 #24
0
 public static bool ChangeStatus(int ID)
 {
     using (var db = new OnlineShopEntities())
     {
         var user = db.Users.Find(ID);
         user.Status = !user.Status;
         db.SaveChanges();
         return(user.Status);
     }
 }
예제 #25
0
 public static int DeleteUser(int ID)
 {
     using (var db = new OnlineShopEntities())
     {
         var user = db.Users.Find(ID);
         db.Users.Remove(user);
         var result = db.SaveChanges();
         return(result);
     }
 }
예제 #26
0
 public static int DeleteOrderDetail(int ID)
 {
     using (var db = new OnlineShopEntities())
     {
         var orderDetail = db.OrderDetails.Find(ID);
         db.OrderDetails.Remove(orderDetail);
         var result = db.SaveChanges();
         return(result);
     }
 }
예제 #27
0
        public ActionResult Edit(int?id, string Firstname, string Lastname, string Email, string Password, string RepeatPassword)
        {
            if (id != null && Firstname != string.Empty && Lastname != string.Empty && Email != string.Empty && Password != string.Empty)
            {
                if (RepeatPassword == Password)
                {
                    Customer existCus = db.Customers.FirstOrDefault(cus => cus.Email == Email);
                    if (existCus == null)
                    {
                        Customer customer = db.Customers.FirstOrDefault(cus => cus.id == id);
                        if (customer != null)
                        {
                            customer.Firstname = Firstname;
                            customer.Lastname  = Lastname;
                            customer.Email     = Email;
                            customer.Password  = Password;

                            db.SaveChanges();

                            return(RedirectToAction("Index", new { id = id }));
                        }
                        else
                        {
                            ViewBag.Error = "bele bir customer yoxdur.";
                        }
                    }
                    else
                    {
                        ViewBag.Error = "bele bir email movcuddur.";
                    }
                }
                else
                {
                    ViewBag.Error = "Password and Repeat Password doesn't match.";
                }
            }
            else
            {
                ViewBag.Error = "please fill all the fields.";
            }
            return(View());
        }
 private static void InsertContentTag(int contentID, string tagID)
 {
     using (var db = new OnlineShopEntities())
     {
         var contentTag = new ContentTag {
             ContentID = contentID, TagID = tagID
         };
         db.ContentTags.Add(contentTag);
         db.SaveChanges();
     }
 }
 private static void InsertTag(string id, string name)
 {
     using (var db = new OnlineShopEntities())
     {
         var tag = new Tag {
             ID = id, Name = name
         };
         db.Tags.Add(tag);
         db.SaveChanges();
     }
 }
예제 #30
0
        public static int InsertUser(User user)
        {
            var result = 0;

            using (var db = new OnlineShopEntities())
            {
                db.Users.Add(user);
                result = db.SaveChanges();
                return(result);
            }
        }