public JsonResult AddWord(int groupId, string word, string wordTr)
        {
            Words     words;
            UserWords userWord;
            int       userId = Convert.ToInt32(Session[Sys.userId]);

            try
            {
                using (entities = new wwbEntities())
                {
                    /* If group not exist then insert then just take id below */
                    words = entities.Words
                            .Where(w => w.word == word && w.word_translate == wordTr)
                            .FirstOrDefault();

                    if (words == null)
                    {
                        words                = new Words();
                        words.group_id       = groupId;
                        words.word           = word;
                        words.word_translate = wordTr;

                        entities.Words.Add(words);
                        entities.SaveChanges();
                    }
                }

                using (entities = new wwbEntities())
                {
                    /* Already exists */
                    userWord = entities.UserWords
                               .Where(uw => (uw.user_id == userId && uw.word_id == words.word_id))
                               .FirstOrDefault();

                    if (userWord != null)
                    {
                        return(Json(WordAddingStatus.AlreadyExist, JsonRequestBehavior.AllowGet));
                    }

                    userWord         = new UserWords();
                    userWord.word_id = words.word_id;
                    userWord.user_id = userId;

                    entities.UserWords.Add(userWord);
                    entities.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(Json(WordAddingStatus.Fail, JsonRequestBehavior.AllowGet));
            }


            return(Json(WordAddingStatus.Success, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AddGroup(string groupName)
        {
            Groups     group;
            UserGroups userGroup;
            int        userId = Convert.ToInt32(Session[Sys.userId]);

            try
            {
                using (entities = new wwbEntities())
                {
                    /* If group not exist then insert then just take id below */
                    group = entities.Groups
                            .Where(g => g.group_name == groupName)
                            .FirstOrDefault();

                    if (group == null)
                    {
                        group            = new Groups();
                        group.group_name = groupName;

                        entities.Groups.Add(group);
                        entities.SaveChanges();
                    }
                }
                using (entities = new wwbEntities())
                {
                    /* Already exists */ //TODO : There is possibly a problem. check it
                    userGroup = entities.UserGroups
                                .Where(ug => (ug.user_id == userId && ug.group_id == group.group_id))
                                .FirstOrDefault();

                    if (userGroup != null)
                    {
                        return(Json(GroupAddingStatus.AlreadyExist, JsonRequestBehavior.AllowGet));
                    }

                    userGroup          = new UserGroups();
                    userGroup.group_id = group.group_id;
                    userGroup.user_id  = userId;

                    entities.UserGroups.Add(userGroup);
                    entities.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(Json(GroupAddingStatus.Fail, JsonRequestBehavior.AllowGet));
            }


            return(Json(GroupAddingStatus.Success, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddWord()
        {
            if (!isLogged())
            {
                return(RedirectToAction("Index", "Index"));
            }



            List <Group>      userGroupList = new List <Group>();
            List <UserGroups> userGroups    = null;
            List <Groups>     groups        = null;
            Groups            group         = null;
            int userId = Convert.ToInt32(Session[Sys.userId]);


            using (entities = new wwbEntities())
            {
                userGroups = entities.UserGroups
                             .Where(g => (g.user_id == userId))
                             .ToList();

                string s = "";
                if (userGroups != null)
                {
                    foreach (UserGroups ug in userGroups)
                    {
                        group = entities.Groups
                                .Where(g => g.group_id == ug.group_id)
                                .FirstOrDefault();

                        userGroupList.Add(new Group(group.group_id, group.group_name));
                        s += group.group_name + " ";
                    }
                    ViewData[Sys.userGroups] = userGroupList;
                }
            }

            return(View());

            return(View());
        }
Beispiel #4
0
        public JsonResult Login(string mail, string password, bool rememberMe)
        {
            try
            {
                using (entities = new wwbEntities())
                {
                    Users userControl = entities.Users
                                        .Where(u => u.mail == mail)
                                        .FirstOrDefault();


                    if (userControl == null)
                    {
                        return(Json(LoginStatus.UserNotExist, JsonRequestBehavior.DenyGet));
                    }

                    if (!Crypto.VerifyHashedPassword(userControl.password, password))
                    {
                        return(Json(LoginStatus.IncorrectPassword, JsonRequestBehavior.DenyGet));
                    }
                    else
                    {
                        //creating token
                        Session[Sys.userId]     = userControl.user_id;
                        Session[Sys.mail]       = userControl.mail;
                        Session[Sys.firstName]  = userControl.first_name;
                        Session[Sys.lastName]   = userControl.last_name;
                        Session[Sys.birthDate]  = userControl.birth_date;
                        Session[Sys.createDate] = userControl.create_date;

                        Session.Timeout = rememberMe ? 250000 : 720;
                    }
                    return(Json(LoginStatus.Success, JsonRequestBehavior.DenyGet));
                }
            }
            catch (Exception)
            {
                return(Json(LoginStatus.Fail, JsonRequestBehavior.DenyGet));
            }
        }
Beispiel #5
0
        public JsonResult Register(string mail, string password)
        {
            try
            {
                using (entities = new wwbEntities())
                {
                    ////mail control
                    Users userControl = entities.Users
                                        .Where(u => u.mail == mail)
                                        .FirstOrDefault();

                    if (userControl != null)
                    {
                        return(Json(RegisterStatus.MailExist, JsonRequestBehavior.AllowGet));
                    }

                    string hashPassword = Crypto.HashPassword(password);


                    Users user = new Users();
                    user.password    = hashPassword;
                    user.mail        = mail;
                    user.create_date = DateTime.Now;

                    entities.Users.Add(user);


                    entities.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(Json(RegisterStatus.Fail, JsonRequestBehavior.AllowGet));
            }


            return(Json(RegisterStatus.Success, JsonRequestBehavior.AllowGet));
        }