コード例 #1
0
 public ActionResult Save(Category category)
 {
     if (category.CategoryId == 0)
     {
         if (ModelState.IsValid)
         {
             category.CreatedDate = DateTime.Now;
             db.Categories.Add(category);
             db.SaveChanges();
         }
         else
         {
             return(View("New"));
         }
     }
     else
     {
         if (ModelState.IsValid)
         {
             var dbcategory = db.Categories.Single(c => c.CategoryId == category.CategoryId);
             dbcategory.Name        = category.Name;
             dbcategory.Pic         = category.Pic;
             dbcategory.Description = category.Description;
             db.SaveChanges();
         }
         else
         {
             return(View("Edit", category));
         }
     }
     return(RedirectToAction("Index"));
 }
コード例 #2
0
        public IHttpActionResult PostOrder(Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data.."));
            }

            db.Orders.Add(order);
            db.SaveChanges();
            return(Ok());
        }
コード例 #3
0
        public IHttpActionResult PostProduct(Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data"));
            }

            db.Products.Add(product);
            db.SaveChanges();
            return(Ok());
        }
コード例 #4
0
        public IHttpActionResult PostSubcategory(Subcategory subcategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data..."));
            }

            db.Subcategories.Add(subcategory);
            db.SaveChanges();

            return(Created("http://localhost:55437/api/ABC", subcategory));
        }
コード例 #5
0
        public IHttpActionResult PostCategory(Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data.."));
            }

            category.CreatedDate = DateTime.Now;
            db.Categories.Add(category);
            db.SaveChanges();

            return(Created("http://localhost:55437/api/Categoryapi", category));
        }
コード例 #6
0
        public JsonResult AddtoCart(int productid)
        {
            string id             = User.Identity.GetUserId();
            var    product        = db.Products.Single(p => p.ProductId == productid);
            var    isalreadyadded = db.Carts.Count(c => c.ProductId == product.ProductId && c.Id == id);

            if (isalreadyadded == 0)
            {
                Cart c = new Cart
                {
                    Id        = User.Identity.GetUserId(),
                    ProductId = productid,
                    Quantity  = 1,
                    Amount    = product.Price
                };
                db.Carts.Add(c);
                db.SaveChanges();
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }

            // return RedirectToAction("GetProductsByName","Product", new { name = product.Subcategory.Name });
        }
コード例 #7
0
        public IHttpActionResult PostCartItem(Cart cartitem)
        {
            var product = db.Products.Single(p => p.ProductId == cartitem.ProductId);

            cartitem.Amount = product.Price;
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data"));
            }

            db.Carts.Add(cartitem);
            db.SaveChanges();

            return(Ok());
        }
コード例 #8
0
        public IHttpActionResult PostAddress(Address address)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data"));
            }



            db.Addresses.Add(address);
            db.SaveChanges();


            return(Ok());
        }
コード例 #9
0
        public IHttpActionResult UpdateCustomer(string UserId, string ccn)
        {
            Customer customerInDb = db.Customers.SingleOrDefault(c => c.Id == UserId);

            if (customerInDb == null)
            {
                return(NotFound());
            }

            customerInDb.CreditCardNumber = ccn;

            db.SaveChanges();

            return(Ok());
        }
コード例 #10
0
        public ActionResult Save(Subcategory subcategory)
        {
            if (subcategory.SubcategoryId == 0)
            {
                if (ModelState.IsValid)
                {
                    subcategory.CreatedDate = DateTime.Now;
                    db.Subcategories.Add(subcategory);
                    db.SaveChanges();
                }
                else
                {
                    var vm = new SubcategoryViewModel
                    {
                        SubCategory    = subcategory,
                        DepartmentList = db.Categories.ToList(),
                        CategoryList   = db.Subcategories.ToList()
                    };
                    return(View("New", vm));
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var dbsubcategory = db.Subcategories.Single(s => s.SubcategoryId == subcategory.SubcategoryId);
                    dbsubcategory.Name         = subcategory.Name;
                    dbsubcategory.ModifiedDate = DateTime.Now;
                    dbsubcategory.Pic          = subcategory.Pic;
                    dbsubcategory.ParentId     = subcategory.ParentId;
                    dbsubcategory.Description  = subcategory.Description;
                    dbsubcategory.CategoryId   = subcategory.CategoryId;

                    db.SaveChanges();
                }
                else
                {
                    var vm = new SubcategoryViewModel
                    {
                        SubCategory    = subcategory,
                        DepartmentList = db.Categories.ToList(),
                        CategoryList   = db.Subcategories.ToList()
                    };
                    return(View("Edit", vm));
                }
            }
            return(RedirectToAction("Index", "SubCategory"));
        }
コード例 #11
0
 public ActionResult SaveAddress(Address address)
 {
     if (address.AddressId == 0)
     {
         address.Id = User.Identity.GetUserId();
         db.Addresses.Add(address);
     }
     else
     {
         var addressInDb = db.Addresses.Single(a => a.AddressId == address.AddressId);
         addressInDb.City          = address.City;
         addressInDb.HouseNo       = address.HouseNo;
         addressInDb.Colony_Street = address.Colony_Street;
         addressInDb.StateId       = address.StateId;
         addressInDb.Pincode       = address.Pincode;
     }
     db.SaveChanges();
     return(RedirectToAction("YourAddresses"));
 }
コード例 #12
0
        public ActionResult Save(Product product)
        {
            var parentids = db.Subcategories.Where(p => p.ParentId != null).Select(p => p.ParentId).ToList();

            if (product.ProductId == 0)
            {
                if (ModelState.IsValid)
                {
                    product.CreatedDate = DateTime.Now;
                    db.Products.Add(product);
                    db.SaveChanges();
                }

                else
                {
                    var vm = new ProductViewModel
                    {
                        Product         = product,
                        SubcategoryList = db.Subcategories
                                          .Where(e => !parentids.Contains(e.SubcategoryId)).ToList()
                    };
                    return(View("New", vm));
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var dbproduct = db.Products.Single(p => p.ProductId == product.ProductId);
                    dbproduct.Name          = product.Name;
                    dbproduct.ModifiedDate  = DateTime.Now;
                    dbproduct.Pic           = product.Pic;
                    dbproduct.Description   = product.Description;
                    dbproduct.Price         = product.Price;
                    dbproduct.NumberOfStock = product.NumberOfStock;
                    dbproduct.SubcategoryId = product.SubcategoryId;
                    db.SaveChanges();
                }
                else
                {
                    var vm = new ProductViewModel
                    {
                        Product         = product,
                        SubcategoryList = db.Subcategories
                                          .Where(e => !parentids.Contains(e.SubcategoryId)).ToList()
                    };

                    return(View("Edit", vm));
                }
            }
            return(RedirectToAction("Index"));
        }
コード例 #13
0
        public IHttpActionResult PostUser(AspNetUser user)
        {
            var userInDb = db.AspNetUsers.Single(u => u.Id == user.Id);

            if (userInDb == null)
            {
                return(NotFound());
            }
            //  userInDb.Email = user.Email;
            userInDb.PhoneNumber = user.PhoneNumber;
            userInDb.UserName    = user.UserName;
            userInDb.Email       = user.UserName;
            db.SaveChanges();

            return(Ok());
        }
コード例 #14
0
 public ActionResult SaveProfile(AspNetUser user)
 {
     if (ModelState.IsValid)
     {
         var userInDb = db.AspNetUsers.Single(u => u.Id == user.Id);
         userInDb.Email       = user.UserName;
         userInDb.UserName    = user.UserName;
         userInDb.PhoneNumber = user.PhoneNumber;
         db.SaveChanges();
         return(RedirectToAction("AdminProfile"));
     }
     else
     {
         return(View("EditAdminProfile", user));
     }
 }
コード例 #15
0
        public IHttpActionResult PostAdmin(AspNetUser admin)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data"));
            }

            var userInDb = db.AspNetUsers.Single(u => u.Id == admin.Id);

            userInDb.Email       = admin.UserName;
            userInDb.UserName    = admin.UserName;
            userInDb.PhoneNumber = admin.PhoneNumber;
            db.SaveChanges();


            return(Ok());
        }
コード例 #16
0
        public IHttpActionResult  DeleteSubcategory(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid student id"));
            }

            using (var ctx = new AkankshaEntities())
            {
                var student = ctx.Subcategories
                              .Where(s => s.SubcategoryId == id)
                              .FirstOrDefault();

                ctx.Entry(student).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }