public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("ConfirmPassword", "Passwords are not confirmed");
                return(View(model));
            }

            using (GainBargainContext db = new GainBargainContext())
            {
                if (db.Users.Any(x => x.Email == model.Email))
                {
                    ModelState.AddModelError("Email", "This email is already taken");
                    model.Email = "";
                    return(View(model));
                }

                User user = new User()
                {
                    Email    = model.Email,
                    Password = model.Password
                };

                db.Users.Add(user);
                db.SaveChanges();

                UserRole userRole = new UserRole()
                {
                    UserId = user.Id,
                    RoleId = 2
                };

                db.UserRoles.Add(userRole);
                db.SaveChanges();
            }

            return(RedirectToAction("Login", "Account"));
        }
        public ActionResult CreateParsingSource(ParserSource source)
        {
            if (db.Categories.Any(cat => cat.Id == source.CategoryId) &&
                db.Markets.Any(m => m.Id == source.MarketId) &&
                !db.ParserSources.Any(s => s.Url == source.Url))
            {
                db.ParserSources.Add(source);
                db.SaveChanges();

                return(RedirectToAction("Sources"));
            }

            ViewBag.ErrorMessage = "You typed wrong ids or URL!";
            return(View("Error"));
        }
        public void CreateAssociation(int productId, List <int> associations)
        {
            foreach (var ass in associations)
            {
                if (ass != 0)
                {
                    var p = new Association()
                    {
                        AccosiationId = ass, ProductId = productId
                    };
                    db.Associations.Add(p);
                }

                db.SaveChanges();
            }
        }
 public void AddFavoriteProduct(FavoriteProduct product)
 {
     db.FavoriteProducts.Add(product);
     db.SaveChanges();
 }
 public void AddFavoriteCategory(FavoriteCategory category)
 {
     db.FavoriteCategories.Add(category);
     db.SaveChanges();
 }