public JsonResult RegisterUser(CUser model)
        {
            CUser cUser = new CUser();

            if (!cUser.userNameAvailable(model.userName))
            {
                return(Json("Användarnamn upptaget. Välj ett annat namn.", JsonRequestBehavior.AllowGet));
            }
            if (!cUser.emailAvailable(model.email))
            {
                return(Json("Denna emailadress finns redan i systemet.", JsonRequestBehavior.AllowGet));
            }

            string resultText = "Success";

            try
            {
                pdsTidRedLiveEntities db = new pdsTidRedLiveEntities();
                userTbl u = new userTbl();
                u.userName   = model.userName;
                u.email      = model.email;
                u.userRoleId = model.userRoleId;
                u.password   = model.password;

                u.regDate = System.DateTime.Now;

                db.userTbl.Add(u);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                resultText = "Error while inserting user. Error message : " + ex.Message;
            }
            return(Json(resultText, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        /*
         * public int getAllUsersFromTheSameGender(char gender)
         * {//get all the users from the same gender 'F' = female or 'M'=male - aware\unaware candidates and all the students
         *  return getAllCandidatesFromTheSameGender(gender).Count + getAllStudentsFromTheSameGender(gender).Count;
         * }*/

        /*Add functions*/
        public static void addUserToUsers(userTbl user, List <userTbl> users)
        {
            using (var db = new HeznekDB())
            {
                db.userTbl.Add(user);
                db.SaveChanges();
            }
        }
예제 #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            userTbl userTbl = await db.userTbls.FindAsync(id);

            db.userTbls.Remove(userTbl);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public async Task <ActionResult> Edit([Bind(Include = "userId,userName,phoneNum,Magnitude,Landitude,creditNum,creditType,ruleId,Name,Email,Password")] userTbl userTbl)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userTbl).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ruleId = new SelectList(db.ruleTbls, "ruleId", "ruleName", userTbl.ruleId);
            return(View(userTbl));
        }
예제 #5
0
 public static List<userTbl> getAllUsersByType(int numType)
 {
     List<loginAndPermissions> usersLogin = getLoginList();
     List<userTbl> users = new List<userTbl>();
     foreach(var user in usersLogin)
     {
         if(user.userType == numType)
         {
             userTbl userToList = ForeignKeys.getUserConnectedByID(user.id);
             users.Add(userToList);
         }
     }
     return users;
 }
예제 #6
0
        // GET: userTbls/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            userTbl userTbl = await db.userTbls.FindAsync(id);

            if (userTbl == null)
            {
                return(HttpNotFound());
            }
            return(View(userTbl));
        }
예제 #7
0
        // GET: userTbls/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            userTbl userTbl = await db.userTbls.FindAsync(id);

            if (userTbl == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ruleId = new SelectList(db.ruleTbls, "ruleId", "ruleName", userTbl.ruleId);
            return(View(userTbl));
        }
예제 #8
0
        /*removal functions*/

        public static void removeUserFromList(userTbl userToRemove)
        {
            using (var db = new HeznekDB())
            {
                List <userTbl> users = getAllUsers();

                foreach (userTbl user in users)
                {
                    if (user.id.Equals(userToRemove.id))
                    {
                        db.userTbl.Remove(user);
                    }
                }
            }
        }
예제 #9
0
        /*update functions*/
        public static void updateUserInList(userTbl updatedUser)
        {
            using (var db = new HeznekDB())
            {
                List <userTbl> users = getAllUsers();

                foreach (userTbl user in users)
                {
                    if (user.id.Equals(updatedUser.id))
                    {
                        db.userTbl.Remove(user);
                        db.userTbl.Add(updatedUser);
                    }
                }
            }
        }
예제 #10
0
        public async Task <ActionResult> Create([Bind(Include = "userId,userName,phoneNum,Magnitude,Landitude,creditNum,creditType,ruleId,Name,Email,Password")] userTbl userTbl)
        {
            if (ModelState.IsValid)
            {
                userTbl.userName  = "";
                userTbl.Landitude = 0.0f;
                userTbl.Magnitude = 0.0f;
                // assing User role 2 ==> User
                userTbl.ruleId = 2;

                db.userTbls.Add(userTbl);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.ruleId = new SelectList(db.ruleTbls, "ruleId", "ruleName", userTbl.ruleId);
            return(View(userTbl));
        }
예제 #11
0
        public ActionResult LoginUser([Bind(Include = "Email,Password")] userTbl userTbl)
        {
            var user = db.userTbls.FirstOrDefault(x => x.Email == userTbl.Email);

            if (user == null)
            {
                ViewBag.Errors = "Password was incorrect";
                return(View("LoginUser"));
            }

            if (user.Password == userTbl.Password)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Errors = "Password was incorrect";
                return(View("LoginUser"));
            }
        }
        public JsonResult LoginUser(CUser model)
        {
            pdsTidRedLiveEntities db = new pdsTidRedLiveEntities();

            userTbl user   = db.userTbl.SingleOrDefault(x => x.userName == model.userName && x.password == model.password);
            string  result = "Felaktigt användarnamn eller lösenord";

            if (user != null)
            {
                Session["userId"]   = user.userId;
                Session["userName"] = user.userName;
                if (user.userRole.roleLevel == 10)
                {
                    result = "Admin";
                }
                else
                {
                    result = "User";
                }
                Session["roleLevel"] = user.userRole.roleLevel.ToString();
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }