Exemple #1
0
        public ActionResult Message(string Address)
        {
            int total = 0;

            foreach (var variant in db.Carts)
            {
                if (variant.PersonId.Equals(Session["EmailId"].ToString()))
                {
                    total = total + variant.TotalPrice;
                }
            }
            Order CurrOrder = new Order();

            CurrOrder.PersonId    = Session["EmailId"].ToString();
            CurrOrder.Address     = Address;
            CurrOrder.TotalAmount = total;

            db.Orders.Add(CurrOrder);
            db.SaveChanges();

            int rowno = 0;

            foreach (var order in db.Orders)
            {
                rowno = order.OrderId;
            }

            //foreach (var variant in db.Carts)
            //{
            var results = (from a in db.Carts select a).ToList();

            foreach (var variant in results)
            {
                if (variant.PersonId.Equals(Session["EmailId"].ToString()))
                {
                    OrderedProduct p = new OrderedProduct();
                    p.VariantId = variant.VariantId;

                    p.OrderId = rowno;

                    p.Quantity = variant.Count;

                    db.OrderedProducts.Add(p);

                    db.SaveChanges();
                }
            }


            foreach (var variant in results)
            {
                if (variant.PersonId.Equals(Session["EmailId"].ToString()))
                {
                    db.Carts.Remove(variant);
                    db.SaveChanges();
                }
            }

            return(View());
        }
        public IActionResult Post(Product model)
        {
            //_db.Products.Add(model);
            _db.Set <Product>().Add(model);
            _db.SaveChanges();

            return(Ok(model));
        }
 public ActionResult Create(Product product)
 {
     if (ModelState.IsValid)
     {
         _db.Products.Add(product);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Exemple #4
0
        public ActionResult Create(UserProfile userprofile)
        {
            if (ModelState.IsValid)
            {
                db.UserProfiles.Add(userprofile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userprofile));
        }
        public ActionResult Create(Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplier));
        }
Exemple #6
0
        public ActionResult Create(Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
Exemple #7
0
 public ActionResult addproduct(productrecord p)
 {
     if (ModelState.IsValid)
     {
         obj.productrecords.Add(p);
         obj.SaveChanges();
         return(View("Index"));
     }
     else
     {
         return(View());
     }
 }
        public ActionResult AddToBasket(int ProductID)
        {
            var product = _ProductDb.Products.Where(x => x.ProductID == ProductID).First();

            product.BasketID = 1;

            if (ModelState.IsValid)
            {
                _ProductDb.Entry(product).State = EntityState.Modified;
                _ProductDb.SaveChanges();
                return(RedirectToAction("Index", "Basket"));
            }
            return(View());
        }
        public ActionResult Register(Person Model)
        {
            //if (!ValidateSignUp(viewModel))
            //    return View(viewModel);

            try
            {
                if (ModelState.IsValid)
                {
                    var get_user = db.Persons.FirstOrDefault(p => p.EmailId == Model.EmailId);

                    // insert the user into the database!

                    if (get_user == null)
                    {
                        db.Persons.Add(Model);
                        db.SaveChanges();
                        return(RedirectToAction("Login", "Account"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "EmailId already exists");
                        return(View());
                    }
                }
            }

            catch (Exception ex)
            {
                ModelState.AddModelError("ModelStateException", ex);
            }


            return(View(Model));
        }
        public static Result EditProduct(ProductModel model)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var item = db.Products.Find(model.ProductID);
                    if (item != null)
                    {
                        item.ProductModelToProductMapExtension(model);

                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(new Exception("Unable to edit Product"));
            }

            return(result);
        }
Exemple #11
0
        public ActionResult EditFavoriteAd(Guid productId)
        {
            string myUserId = User.Identity.GetUserId();

            UserFavoriteAd ufa = new UserFavoriteAd
            {
                UserId    = myUserId,
                ProductId = productId
            };

            bool response;
            IEnumerable <UserFavoriteAd> result = _productDb.UserFavoriteAds.Where(x => x.UserId == myUserId)
                                                  .Where(x => x.ProductId == productId);

            if (!result.Any())
            {
                _productDb.UserFavoriteAds.Add(ufa);
                response = true;
            }
            else
            {
                _productDb.UserFavoriteAds.Remove(result.FirstOrDefault());
                response = false;
            }
            _productDb.SaveChanges();
            return(Json(new { ifFavorited = response }));
        }
        public ActionResult Remove(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cart variant = db.Carts.Find(Id);

            if (variant == null)
            {
                return(HttpNotFound());
            }

            db.Carts.Remove(variant);
            db.SaveChanges();

            return(RedirectToAction("ShowCart"));
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (var db = new ProductDb())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
        public static Result SaveProduct(ProductModel model)
        {
            Result result = new Result();

            try
            {
                Product product = new Product();
                product.ProductModelToProductMapExtension(model);

                using (var db = new ProductDb())
                {
                    db.Products.Add(product);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result = new Result(new Exception("Unable to add new product"));
            }

            return(result);
        }
        public static Result DeleteProduct(int Id)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var ProductModel = db.Products.Find(Id);
                    if (ProductModel != null)
                    {
                        db.Entry(ProductModel).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(ex);
            }
            return(result);
        }
        public static Result Delete(int id)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var item = db.Products.Find(id);
                    if (item != null)
                    {
                        db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(new Exception("Unable to delete Product"));
            }
            return(result);
        }
        public ActionResult Create(ImageViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ProductImages fileUploadModel = new ProductImages();
            Guid          id = (Guid)TempData["ProductId"];

            foreach (var item in model.File)
            {
                byte[] uploadFile = new byte[item.InputStream.Length];
                item.InputStream.Read(uploadFile, 0, uploadFile.Length);
                fileUploadModel.ProductId = id;
                fileUploadModel.File      = uploadFile;

                db.ProductImages.Add(fileUploadModel);
                db.SaveChanges();
            }
            TempData["ImageUploadFlag"] = true;
            return(RedirectToAction("Index", "Ads"));
        }
Exemple #18
0
 public void SaveChanges()
 {
     context.SaveChanges();
 }