Пример #1
0
        public ActionResult Login(UserModel model)
        {
            if (ModelState.IsValid)
            {
                using (var context = new Context())
                {
                    Users_Table user = context.Users_Table
                                       .Where(u => u.Username == model.UserName && u.Password == model.Password)
                                       .FirstOrDefault();

                    if (user != null)
                    {
                        Session["UserName"] = user.Username;
                        Session["UserId"]   = user.Id;
                        return(RedirectToAction("GetList", "Registration"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "არასწორი მომხმარებელი ან პაროლი");
                        return(View(model));
                    }
                }
            }
            else
            {
                return(View(model));
            }
        }
Пример #2
0
        public void Destroy(UserViewModel user)
        {
            var entity = new Users_Table();

            entity.UserID = user.UserID;
            entities.Users_Table.Attach(entity);
            entities.Users_Table.Remove(entity);
            entities.SaveChanges();
        }
Пример #3
0
        public void Create(UserViewModel user)
        {
            var entity = new Users_Table();

            entity.FullName = user.FullName;
            entity.UserName = user.Username;
            entity.Password = user.Password;
            entity.UserType = user.UserType;

            entity.Status = user.userstatus;
            entities.Users_Table.Add(entity);
            entities.SaveChanges();

            user.UserID = entity.UserID;
        }
Пример #4
0
        public ActionResult Edit(RegistrationViewModel rvm)
        {
            Context      context = new Context();
            Person_Table pt      = context.Person_Table.Where(u => u.Id == rvm.Id).FirstOrDefault();
            Users_Table  ut      = pt.Users_Table.FirstOrDefault() == null ? new Users_Table() : pt.Users_Table.FirstOrDefault();

            ut.Username  = rvm.Username;
            ut.Password  = rvm.Password;
            ut.Email     = rvm.Email;
            pt.FirstName = rvm.FirstName;
            pt.LastName  = rvm.LastName;
            pt.Gender    = rvm.Gender;
            pt.Users_Table.Add(ut);
            context.SaveChanges();
            return(RedirectToAction("GetList", "Registration"));
        }
Пример #5
0
 public bool DeleteUser(UsersModel user)
 {
     //using (ProjectManagerEntities dbContext = new ProjectManagerEntities())
     //{
         try
         {
             var userData = new Users_Table { User_ID = user.User_ID };
             dbContext.Entry(userData).State = EntityState.Deleted;
             dbContext.SaveChanges();
         }
         catch (Exception e)
         {
             return false;
         }
         return true;
     }
Пример #6
0
        public ActionResult Add(RegistrationViewModel p)
        {
            ViewBag.Message = p.FirstName + " " + p.LastName;
            Context     Pmodel = new Context();
            Users_Table users  = new Users_Table {
                Username = p.Username, Password = p.Password, Email = p.Email
            };
            List <Users_Table> userlist = new List <Users_Table>();

            userlist.Add(users);
            //Pmodel.Users_Table.Add(users);
            Pmodel.Person_Table.Add(new Person_Table {
                FirstName = p.FirstName, LastName = p.LastName, Gender = p.Gender, Users_Table = userlist
            });
            Pmodel.SaveChanges();
            return(RedirectToAction("GetList", "Registration"));
        }
Пример #7
0
        public ActionResult Edit(int Id)
        {
            Context               context = new Context();
            Person_Table          pt      = context.Person_Table.Where(o => o.Id == Id).FirstOrDefault();
            Users_Table           ut      = pt.Users_Table.FirstOrDefault() == null ? new Users_Table() : pt.Users_Table.FirstOrDefault();
            RegistrationViewModel rvm     = new RegistrationViewModel
            {
                Id        = pt.Id,
                Email     = ut.Email,
                FirstName = pt.FirstName,
                Gender    = pt.Gender,
                LastName  = pt.LastName,
                Username  = ut.Username
            };

            return(View(rvm));
        }
Пример #8
0
        public void Update(UserViewModel user)
        {
            var entity = new Users_Table();

            entity.UserID   = user.UserID;
            entity.FullName = user.FullName;
            entity.UserName = user.Username;
            entity.Password = user.Password;
            entity.UserType = user.UserType;

            entity.Status = user.userstatus;



            entities.Users_Table.Attach(entity);
            entities.Entry(entity).State = EntityState.Modified;
            entities.SaveChanges();
        }
Пример #9
0
        public ActionResult Login(Users_Table user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (LawyersEntities dc = new LawyersEntities())
                    {
                        // Check If Existed Or Not :
                        var u = dc.Users_Table.Single(i => i.UserName == user.UserName &&
                                                      i.Password == user.Password &&
                                                      i.Status == true);
                        if (u != null)
                        {
                            Session["UserID"]   = u.UserID;
                            Session["UserName"] = u.FullName;
                            Session["Password"] = u.Password;
                            Session["UserType"] = u.UserType;

                            if ((string)Session["UserType"] == "1" || (string)Session["UserType"] == "2" || (string)Session["UserType"] == "3")
                            {
                                return(RedirectToAction("Index", "Home"));
                            }
                            else if ((string)Session["UserType"] == "4")
                            {
                                return(RedirectToAction("FamilyForum", "FamilyForum"));
                            }



                            //  User Informations :
                        }
                    }
                }
                catch (Exception)
                {
                    //اذا كان المستخدم اساسا مش موجود في جدول المستخدمين او كلمة المرور خطأ
                    ModelState.AddModelError("", "خطأ في الدخول للنظام");
                }
            }
            return(View(user));
        }
Пример #10
0
        public bool AddUser(UsersModel user)
        {
            using (ProjectManagerEntities dbContext = new ProjectManagerEntities())
            {
                
                try
                {
                    if (user.User_ID == 0)
                    {
                        Users_Table userData = new Users_Table()
                        {
                            Employee_ID = user.Employee_ID,
                            First_Name = user.First_Name,
                            Last_Name = user.Last_Name
                        };

                        dbContext.Users_Table.Add(userData);
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        var userData = dbContext.Users_Table.Where(c => c.User_ID == user.User_ID).First();
                        if (userData != null)
                        {
                            userData.First_Name = user.First_Name;
                            userData.Last_Name = user.Last_Name;
                            userData.Employee_ID = user.Employee_ID;
                            dbContext.SaveChanges();
                        }
                    }
                }
                catch (Exception e)
                {
                    return false;
                }
                return true;
            }

        }