Beispiel #1
0
        public ActionResult Update(Users model)
        {
            using (var context = new DBContexts())
            {
                var  userList = context.Users.Where(x => x.UserId != model.UserId).ToList();
                bool dublura  = false;

                foreach (var user in userList)
                {
                    if (user.UserName == model.UserName)
                    {
                        dublura = true;
                    }
                }

                if (dublura == false)
                {
                    var original = context.Users.Find(model.UserId);
                    context.Entry(original).CurrentValues.SetValues(model);
                    context.SaveChanges();
                }
                else
                {
                    TempData["msg"] = "<script>alert('Acest Username este deja folosit! ');</script>";
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult GetAllForValidation()
        {
            using (var context = new DBContexts())
            {
                var userList = context.Users.Where(x => x.ValidatedUser == false).ToList();

                return(View(userList));
            }
        }
 public ActionResult ValidateStore(int?id)
 {
     using (var context = new DBContexts())
     {
         var originalUser = context.Users.Where(x => x.UserId == id).FirstOrDefault();
         var user         = new Users();
         user = originalUser;
         user.ValidatedUser = true;
         context.Entry(originalUser).CurrentValues.SetValues(user);
         context.SaveChanges();
     }
     return(RedirectToAction("GetAllForValidation", "Stores"));
 }
Beispiel #4
0
 public ActionResult Contact(Contact model)
 {
     if (ModelState.IsValid)
     {
         using (var context = new DBContexts())
         {
             context.Contact.Add(model);
             context.SaveChanges();
             TempData["msg"] = "<script>alert(' Mesajul a fost trimis cu succes, Va multumim ! ');</script>";
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         TempData["msg"] = "<script>alert('Ne pare rau dar toate campurile sunt obligatorii pentru formularul de contact ! ');</script>";
         return(RedirectToAction("Index"));
     }
 }
        public ActionResult AddProduct(int?id)
        {
            using (var context = new DBContexts())
            {
                var user = context.Users.Where(x => x.UserId == id).FirstOrDefault();

                if (user.ValidatedUser == true)
                {
                    Product prod = new Product();
                    prod.UserId = user.UserId;
                    return(View(prod));
                }
                else
                {
                    return(View("NotValidUser"));
                }
            }
        }
Beispiel #6
0
        public ActionResult Register(Users model)
        {
            var isValid = true;

            model.ValidatedUser = false;

            if (!ModelState.IsValid)
            {
                isValid = false;
            }
            using (var context = new DBContexts())
            {
                model.Role = "client";
                var  userList = context.Users.ToList();
                bool dublura  = false;

                foreach (var user in userList)
                {
                    if (user.UserName == model.UserName)
                    {
                        dublura = true;
                    }
                }

                if (dublura == false && isValid == true)
                {
                    context.Users.Add(model);
                    context.SaveChanges();
                    TempData["msg"] = "<script>alert('Contul dumneavoastra a fost inregistrat cu succes. Va rugam asteptati ca acesta sa fie validat de catre admin pentru a putea adauga produse ');</script>";
                }
                else if (dublura == true)
                {
                    TempData["msg"] = "<script>alert('Ne pare rau dar acest username este deja folosit! ');</script>";
                }
                else if (isValid == false)
                {
                    TempData["msg"] = "<script>alert('Ne pare rau dar pentru inregistrare toate campurile sunt obligatorii !! ');</script>";
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #7
0
        public ActionResult Update(string id)
        {
            Users currentUserInfo = new Users();

            if (id != null)
            {
                var userId = Int32.Parse(id);

                using (var context = new DBContexts())
                {
                    currentUserInfo = context.Users.Find(userId);
                }

                return(View(currentUserInfo));
            }
            else
            {
                return(View(currentUserInfo));
            }
        }
 public ActionResult AddProduct(Product model, HttpPostedFileBase image1)
 {
     if (ModelState.IsValid)
     {
         using (var context = new DBContexts())
         {
             if (image1 != null)
             {
                 model.Picture = new byte[image1.ContentLength];
                 image1.InputStream.Read(model.Picture, 0, image1.ContentLength);
             }
             context.Product.Add(model);
             context.SaveChanges();
             TempData["msg"] = "<script>alert('Produs adaugat cu succes ');</script>";
             return(RedirectToAction("AddProduct", "Stores", new { id = model.UserId }));
         }
     }
     else
     {
         TempData["msg"] = "<script>alert('Ne pare rau dar toate campurile in afara de Descriere sunt obligatorii !! ');</script>";
         return(View(model));
     }
 }
Beispiel #9
0
 public BaseRepository(DBContexts contexts)
 {
     _dbContexts = contexts;
     _dbSet      = _dbContexts.Set <TEntity>();
     _dbSet.AsNoTracking();
 }
Beispiel #10
0
        public ActionResult SignIn(Users model)
        {
            Users findAdmin = new Users();

            if (!String.IsNullOrEmpty(model.UserName) && !String.IsNullOrEmpty(model.Password))
            {
                using (var context = new DBContexts())
                {
                    findAdmin = context.Users.Where(x => x.UserName == "admin" && x.Password == "admin" && x.Role == "admin").FirstOrDefault();
                }
                if (model.UserName == findAdmin.UserName && model.Password == findAdmin.Password)
                {
                    try
                    {
                        var identity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Name, findAdmin.UserName),
                            new Claim(ClaimTypes.Role, findAdmin.Role),
                            new Claim(ClaimTypes.UserData, findAdmin.UserId.ToString()),
                        }, "ApplicationCookie");

                        var ctx         = Request.GetOwinContext();
                        var authManager = ctx.Authentication;

                        authManager.SignIn(identity);
                        TempData["msg"] = "<script>alert('Bine ati venit admin !');</script>";

                        return(Redirect(GetRedirectUrl(model.ReturnUrl)));
                    }
                    catch (Exception) { }
                }
                else
                {
                    using (var context = new DBContexts())
                    {
                        var findUser = context.Users.ToList().Where(x => x.UserName == model.UserName && x.Password == model.Password).FirstOrDefault();
                        if (findUser != null)
                        {
                            try
                            {
                                var identity = new ClaimsIdentity(new[] {
                                    new Claim(ClaimTypes.Name, model.UserName),
                                    new Claim(ClaimTypes.Role, "user"),
                                    new Claim(ClaimTypes.UserData, findUser.UserId.ToString())
                                }, "ApplicationCookie");

                                var ctx         = Request.GetOwinContext();
                                var authManager = ctx.Authentication;

                                authManager.SignIn(identity);
                                TempData["msg"] = "<script>alert('Bine ati venit !');</script>";

                                return(Redirect(GetRedirectUrl(model.ReturnUrl)));
                            }
                            catch (Exception) { }
                        }
                    }
                }
            }
            else
            {
                TempData["msg"] = "<script>alert('Ne pare rau dar campurile sunt invalide !');</script>";
            }

            return(RedirectToAction("Index", "Home"));
        }