Esempio n. 1
0
 public ActionResult XacThucDangNhap(USER model)
 {
     if (!ModelState.IsValidField("USERNAME") && !ModelState.IsValidField("PASSWORD"))
     {
         ViewBag.PreviousPage       = "Trang Chủ";
         ViewBag.PreviousAction     = "TrangChu";
         ViewBag.PreviousController = "FrontEnd";
         return(View("DangNhap", model));
     }
     else
     {
         using (var DBEntities = new PartTimeJobEntitiesEntities())
         {
             USER getUser = (from user in DBEntities.USERs
                             where user.USERNAME == model.USERNAME && user.PASSWORD == model.PASSWORD
                             select user).FirstOrDefault <USER>();
             if (getUser != null)
             {
                 Session["userID"]   = getUser.USER_ID;
                 Session["userName"] = getUser.USERNAME;
                 Session["userRole"] = getUser.ROLE_ID;
                 return(RedirectToAction("TrangChu", "FrontEnd"));
             }
             else
             {
                 ViewBag.PreviousPage       = "Trang Chủ";
                 ViewBag.PreviousAction     = "TrangChu";
                 ViewBag.PreviousController = "FrontEnd";
                 ViewBag.Error = "Tài khoản hoặc mật khẩu không đúng !";
                 return(View("DangNhap", model));
             }
         }
     }
 }
 public int layUserIdTuFacebookID(string facebookID)
 {
     using (var DBEntities = new PartTimeJobEntitiesEntities())
     {
         int getID = (from user in DBEntities.USERs
                      where user.FACEBOOK_ID == facebookID
                      select user.USER_ID).FirstOrDefault <int>();
         return(getID);
     }
 }
 public USER layUserTuUserID(int userID)
 {
     using (var DBEntities = new PartTimeJobEntitiesEntities())
     {
         USER getUser = (from user in DBEntities.USERs
                         where user.USER_ID == userID
                         select user).FirstOrDefault <USER>();
         return(getUser);
     }
 }
 //de em check ben em xai gi
 public PROFILE layProfileTuUserID(int userID)
 {
     using (var DBEntities = new PartTimeJobEntitiesEntities())
     {
         PROFILE getProfile = (from profile in DBEntities.PROFILEs
                               where profile.PROFILE_ID == userID
                               select profile).FirstOrDefault <PROFILE>();
         return(getProfile);
     }
 }
Esempio n. 5
0
 // GET: FrontEnd
 public ActionResult TrangChu()
 {
     using (var DBEntities = new PartTimeJobEntitiesEntities())
     {
         Dictionary <int, string> stringCategory = new Dictionary <int, string>();
         List <JOB_CATEGORY>      jobCategory    = (from category in DBEntities.JOB_CATEGORY select category).ToList();
         foreach (JOB_CATEGORY category in jobCategory)
         {
             stringCategory.Add(category.CATEGORY_ID, category.CATEGORY_NAME);
         }
         ViewBag.stringCategory = stringCategory;
     }
     return(View());
 }
 public ActionResult DangKy()
 {
     ViewBag.PreviousPage       = "Trang Chủ";
     ViewBag.PreviousAction     = "TrangChu";
     ViewBag.PreviousController = "FrontEnd";
     using (var DBEntities = new PartTimeJobEntitiesEntities())
     {
         List <ROLE> roleList = (from role in DBEntities.ROLEs
                                 where role.ROLE_ID == 2 || role.ROLE_ID == 3
                                 select role).ToList();
         SelectList resultList = new SelectList(roleList, "ROLE_ID", "ROLE_NAME");
         ViewBag.RoleList = resultList;
         return(View());
     }
 }
        public bool dangKyUserFacebook(string facebookID, Dictionary <string, string> fbInfo)
        {
            using (var DBEntities = new PartTimeJobEntitiesEntities())
            {
                using (var DBTransactions = DBEntities.Database.BeginTransaction())
                {
                    try
                    {
                        USER newUser    = new USER();
                        var  generateID = (from user in DBEntities.USERs
                                           orderby user.USER_ID descending
                                           select user.USER_ID).Take(1).SingleOrDefault();

                        newUser.FACEBOOK_ID   = facebookID;
                        newUser.USERNAME      = facebookID + (generateID + 1);
                        newUser.PASSWORD      = facebookID + "2019group21dotnetNLUHashing";
                        newUser.PASSWORDAGAIN = facebookID + "2019group21dotnetNLUHashing";
                        DateTime dateTime = DateTime.UtcNow.Date;
                        newUser.JOINED_DATE = dateTime.ToString("MM/dd/yyyy");
                        newUser.GMAIL_ID    = Convert.ToString(generateID + 1);
                        newUser.USER_STATUS = (byte)1;
                        newUser.ROLE_ID     = byte.Parse(fbInfo["roleID"]);
                        DBEntities.USERs.Add(newUser);

                        // tao xong user , tien hanh tao profile
                        PROFILE newProfile = new PROFILE();
                        newProfile.FIRST_NAME = fbInfo["fbFirstName"];
                        newProfile.LAST_NAME  = fbInfo["fbLastName"];
                        newProfile.ADDRESS    = fbInfo["fbHometown"];
                        newProfile.BIRTHDAY   = fbInfo["fbBirthday"];
                        newProfile.EMAIL      = fbInfo["fbEmail"];
                        newProfile.SEX        = fbInfo["fbGender"];
                        DBEntities.PROFILEs.Add(newProfile);
                        DBEntities.SaveChanges();
                        DBTransactions.Commit();
                        return(true);
                    }
                    catch (Exception)
                    {
                        DBTransactions.Rollback();
                        DBEntities.Database.ExecuteSqlCommand("USE PartTimeJob;DECLARE @lastIdent int;SET @lastIdent = (SELECT TOP 1 USER_ID FROM[USER] ORDER BY USER_ID DESC);IF @lastIdent IS NULL BEGIN SET @lastIdent=1;END;DBCC CHECKIDENT('dbo.USER',RESEED,@lastIdent);");
                        DBEntities.Database.ExecuteSqlCommand("USE PartTimeJob;DECLARE @lastIdent int;SET @lastIdent = (SELECT TOP 1 PROFILE_ID FROM[PROFILE] ORDER BY PROFILE_ID DESC);IF @lastIdent IS NULL BEGIN SET @lastIdent=1;END;DBCC CHECKIDENT('dbo.PROFILE',RESEED,@lastIdent);");
                        return(false);
                    }
                }
            }
        }
 public bool kiemTraFacebookID(string facebookID)
 {
     using (var DBEntities = new PartTimeJobEntitiesEntities())
     {
         string getFacebookID = (from user in DBEntities.USERs
                                 where user.FACEBOOK_ID == facebookID
                                 select user.FACEBOOK_ID).FirstOrDefault <string>();
         if (getFacebookID != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        public ActionResult XacThucDangKy(USER model)
        {
            {
                if (!ModelState.IsValid)
                {
                    ViewBag.PreviousPage       = "Trang Chủ";
                    ViewBag.PreviousAction     = "TrangChu";
                    ViewBag.PreviousController = "FrontEnd";
                    using (var DBEntities = new PartTimeJobEntitiesEntities())
                    {
                        List <ROLE> roleList = (from role in DBEntities.ROLEs
                                                where role.ROLE_ID == 2 || role.ROLE_ID == 3
                                                select role).ToList();
                        SelectList resultList = new SelectList(roleList, "ROLE_ID", "ROLE_NAME");
                        ViewBag.RoleList = resultList;
                        return(View("DangKy", model));
                    }
                }
                else
                {
                    using (var DBEntities = new PartTimeJobEntitiesEntities())
                    {
                        using (var DBTransactions = DBEntities.Database.BeginTransaction())
                        {
                            USER getUser = (from user in DBEntities.USERs
                                            where user.USERNAME == model.USERNAME
                                            select user).FirstOrDefault <USER>();
                            if (getUser != null)
                            {
                                ViewBag.PreviousPage       = "Trang Chủ";
                                ViewBag.PreviousAction     = "TrangChu";
                                ViewBag.PreviousController = "FrontEnd";
                                List <ROLE> roleList = (from role in DBEntities.ROLEs
                                                        where role.ROLE_ID == 2 || role.ROLE_ID == 3
                                                        select role).ToList();
                                SelectList resultList = new SelectList(roleList, "ROLE_ID", "ROLE_NAME");
                                ViewBag.RoleList      = resultList;
                                ViewBag.UsernameError = "Tài khoản này đã có người sử dụng";
                                return(View("DangKy", model));
                            }
                            else
                            {
                                try
                                {
                                    USER newUser    = model;
                                    var  generateID = (from user in DBEntities.USERs
                                                       orderby user.USER_ID descending
                                                       select user.USER_ID).Take(1).SingleOrDefault();

                                    newUser.FACEBOOK_ID = Convert.ToString(generateID + 1);
                                    newUser.GMAIL_ID    = Convert.ToString(generateID + 1);
                                    newUser.USER_STATUS = (byte)1;
                                    DateTime dateTime = DateTime.UtcNow.Date;
                                    newUser.JOINED_DATE = dateTime.ToString("MM/dd/yyyy");
                                    DBEntities.USERs.Add(newUser);

                                    // tao xong user , tien hanh tao profile
                                    PROFILE newProfile = new PROFILE();
                                    DBEntities.PROFILEs.Add(newProfile);
                                    DBEntities.SaveChanges();
                                    DBTransactions.Commit();
                                    TempData["Message"] = "Chúc mừng tài khoản " + newUser.USERNAME + " đã đăng ký thành công !";
                                    return(RedirectToAction("TrangChu", "FrontEnd"));
                                }catch (Exception)
                                {
                                    DBTransactions.Rollback();
                                    DBEntities.Database.ExecuteSqlCommand("USE PartTimeJob;DECLARE @lastIdent int;SET @lastIdent = (SELECT TOP 1 USER_ID FROM[USER] ORDER BY USER_ID DESC);IF @lastIdent IS NULL BEGIN SET @lastIdent=1;END;DBCC CHECKIDENT('dbo.USER',RESEED,@lastIdent);");
                                    DBEntities.Database.ExecuteSqlCommand("USE PartTimeJob;DECLARE @lastIdent int;SET @lastIdent = (SELECT TOP 1 PROFILE_ID FROM[PROFILE] ORDER BY PROFILE_ID DESC);IF @lastIdent IS NULL BEGIN SET @lastIdent=1;END;DBCC CHECKIDENT('dbo.PROFILE',RESEED,@lastIdent);");
                                    TempData["Message"] = "Có lỗi xảy ra trong hệ thống, vui lòng thử lại sau";
                                    return(RedirectToAction("TrangChu", "FrontEnd"));
                                }
                            }
                        }
                    }
                }
            }
        }