public ActionResult Create([Bind(Include = "ColorId,ColorName,IsActive,IsDelete,DateAdded,DateUpdated")] tbl_Color model)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Color.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "CategoryId,CategoryName,IsActive,IsDelete,DateAdded,DateUpdated,ImagePath")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult AddToCart(AddToCartModel model)
        {
            var repoHelper = new HelperClasses.RepoHelper();

            using (MyAamdhaniEntities context = new MyAamdhaniEntities())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var ProductDetails = repoHelper.GetProductDetails(null, productUniqueId: model.ProductKey);
                        var cartItem       = new CartItem
                        {
                            ProductId    = ProductDetails.ProductId,
                            UnitPrice    = ProductDetails.PiecePrice,
                            Quantity     = model.Quantity,
                            DateAdded    = DateTime.Now,
                            DateModified = DateTime.Now,
                            IsActive     = true,
                            IsDelete     = false,
                            UserId       = 1
                        };

                        context.CartItems.Add(cartItem);

                        context.SaveChanges();
                        transaction.Commit();

                        return(Json(
                                   new AlertModal
                        {
                            IsError = false,
                            Message = "Product Added To Cart Successfully.",
                            AlertClass = "success",
                            RedirectUrl = Url.Action(nameof(Index), "Cart")
                        }, JsonRequestBehavior.AllowGet
                                   ));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return(Json(
                                   new AlertModal
                        {
                            IsError = true,
                            Message = ex.Message,
                            AlertClass = "error",
                            RedirectUrl = Url.Action(nameof(Index), "ShowProduct")
                        }, JsonRequestBehavior.AllowGet
                                   ));
                    }
                }
            }
        }