Beispiel #1
0
 public Boolean GetUserIdentified(int Uid, String Password, String Email)
 {
     using (LOJEntities3 entity = new LOJEntities3())
     {
         User_Identified user_Identified = new User_Identified()
         {
             password = Encrypt(Password),
             id       = Uid,
             email    = Email
         };
         try
         {
             entity.User_Identified.Add(user_Identified);
             if (entity.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 存储que文件记录
        /// </summary>
        /// <param name="queid"></param>
        /// <param name="inputFile"></param>
        /// <param name="outputFile"></param>
        /// <returns></returns>
        public static Boolean SaveRecord(int queid, String inputFile, String outputFile)
        {
            using (LOJEntities3 entity = new LOJEntities3())
            {
                QueInOut queInOut = new QueInOut()
                {
                    queid      = queid,
                    inputfile  = inputFile,
                    outputfile = outputFile
                };

                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.QueInOuts.Add(queInOut);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
        public Boolean GetMarkProblem(int uid, int problemID)
        {
            using (LOJEntities3 entity = new LOJEntities3())
            {
                MarkProblem markProblem = new MarkProblem()
                {
                    uid   = uid,
                    queid = problemID
                };

                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.MarkProblems.Add(markProblem);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #4
0
        public Boolean pushTwitter(int uid, String msg)
        {
            var p = new FluentCommandLineParser();

            using (LOJEntities3 entity = new LOJEntities3())
            {
                Twitter twitter = new Twitter
                {
                    uid  = uid,
                    msg  = msg,
                    date = DateTime.Now.ToString()
                };
                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.Twitters.Add(twitter);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #5
0
 public Boolean GetUserRegister(String Phone, String Gender, String Name, String avator)
 {
     using (LOJEntities3 entity = new LOJEntities3())
     {
         User user = new User()
         {
             phone  = Phone,
             gender = Gender,
             name   = Name,
             time   = DateTime.Now.ToString(),
             avator = avator
         };
         try
         {
             entity.Users.Add(user);
             if (entity.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Beispiel #6
0
 public Boolean deleteTwitter(int uid, int tid)
 {
     using (var dbContext = new LOJEntities3())
     {
         Twitter twi     = new Twitter();
         var     twitter = from e in dbContext.Twitters where e.uid == uid && e.tid == tid select e;
         foreach (var t in twitter)
         {
             twi = t;
             break;
         }
         dbContext.Entry(twi).State = System.Data.Entity.EntityState.Deleted;
         try
         {
             if (dbContext.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Beispiel #7
0
 public String GetAddFriend(int id1, int id2)
 {
     using (LOJEntities3 entity = new LOJEntities3())
     {
         Friend friend = new Friend
         {
             id1 = id1,
             id2 = id2
         };
         try
         {
             entity.Friends.Add(friend);
             if (entity.SaveChanges() > 0)
             {
                 int id = getFriendID(id1, id2);
                 using (LOJEntities3 entity2 = new LOJEntities3())
                 {
                     ChatSession chatSession = new ChatSession
                     {
                         friendid  = id,
                         username1 = getUser(id1).name,
                         username2 = getUser(id2).name,
                         content   = "[]"
                     };
                     try
                     {
                         entity2.ChatSessions.Add(chatSession);
                         if (entity2.SaveChanges() > 0)
                         {
                             return("Success");
                         }
                         else
                         {
                             return("Add Session Failed");
                         }
                     }
                     catch (Exception e)
                     {
                         return("Add Session Failed");
                     }
                 }
             }
             else
             {
                 return("Add Friend Fails");
             }
         }
         catch (Exception e)
         {
             return("Add Friend Fails");
         }
     }
 }
Beispiel #8
0
 public Dictionary <string, object> GetUpdateSendList(int ChatSessionId, String msg, int uid)
 {
     using (var dbContext = new LOJEntities3())
     {
         ChatSession chat    = new ChatSession();
         var         session = from e in dbContext.ChatSessions where e.sessionid == ChatSessionId select e;
         foreach (var u in session)
         {
             chat = u;
             break;
         }
         //List<Dictionary<String, Object>> list = new List<Dictionary<string, object>>();
         JArray array = new JArray();
         if (chat.content != "[]")
         {
             array = JArray.Parse(chat.content);
             // list = JsonConvert.DeserializeObject<List<Dictionary<String, Object>>>(chat.content);
         }
         Dictionary <string, object> dict = new Dictionary <string, object>();
         dict.Add("message", msg);
         dict.Add("uid", uid);
         dict.Add("name", UserInfoController.getUser(uid).name);
         dict.Add("avator", UserInfoController.getUser(uid).avator);
         dict.Add("date", DateTime.Now.ToString());
         String jsonStr = JsonConvert.SerializeObject(dict);
         array.Add((JObject)JsonConvert.DeserializeObject(jsonStr));
         chat.content = array.ToString();
         dbContext.Entry(chat).State = System.Data.Entity.EntityState.Modified;
         try
         {
             if (dbContext.SaveChanges() > 0)
             {
                 return(dict);
             }
             else
             {
                 return(null);
             }
         }
         catch (Exception e)
         {
             return(null);
         }
     }
 }
Beispiel #9
0
        public Boolean GetPushProblem([FromBody] JObject jObject)
        {
            dynamic json        = jObject;
            int     uid         = json.uid;
            String  problemInfo = json.problemInfo;
            String  difficulty  = json.difficulty;
            String  category    = json.category;
            String  title       = json.title;
            String  source      = json.source;

            using (LOJEntities3 entity = new LOJEntities3())
            {
                QuestionSet question = new QuestionSet()
                {
                    userid     = uid,
                    queInfo    = problemInfo,
                    time       = DateTime.Now.ToString(),
                    title      = title,
                    category   = category,
                    difficulty = difficulty,
                    source     = source
                };
                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.QuestionSets.Add(question);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 加入记录
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="qid"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static Boolean SetRecord(int uid, int qid, Boolean status)
        {
            using (LOJEntities3 entity = new LOJEntities3())
            {
                String s = "";
                if (status)
                {
                    s = "AC";
                }
                else
                {
                    s = "WA";
                }
                Record record = new Record()
                {
                    userid     = uid,
                    questionid = qid,
                    status     = s,
                    submittime = DateTime.Now.ToString(),
                };

                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.Records.Add(record);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #11
0
        public Boolean GetPushDiscuss([FromBody] JObject jObject)
        {
            dynamic json  = jObject;
            int     uid   = json.uid;
            String  msg   = json.msg;
            String  type  = json.type;
            String  title = json.title;

            using (LOJEntities3 entity = new LOJEntities3())
            {
                Discuss discuss = new Discuss()
                {
                    userid      = uid,
                    comment     = msg,
                    discuestime = DateTime.Now.ToString(),
                    title       = title,
                    type        = type
                };
                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.Discusses.Add(discuss);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #12
0
        public Boolean GetPushSolutionReply([FromBody] JObject jObject)
        {
            dynamic json       = jObject;
            int     solutionid = json.solutionid;
            String  comment    = json.comment;
            int     userid     = json.userid;

            using (LOJEntities3 entity = new LOJEntities3())
            {
                SolutionComment solutionComment = new SolutionComment()
                {
                    solutionid = solutionid,
                    comment    = comment,
                    userid     = userid,
                    date       = DateTime.Now.ToString()
                };
                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.SolutionComments.Add(solutionComment);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }
Beispiel #13
0
        public Boolean GetPushSolution([FromBody] JObject jObject)
        {
            dynamic json      = jObject;
            int     uid       = json.uid;
            String  answer    = json.answer;
            int     problemid = json.problemid;

            using (LOJEntities3 entity = new LOJEntities3())
            {
                Solution sol = new Solution()
                {
                    userid     = uid,
                    comment    = answer,
                    answerTime = DateTime.Now.ToString(),
                    questionid = problemid
                };
                using (TransactionScope tran = new TransactionScope())
                {
                    try
                    {
                        entity.Solutions.Add(sol);
                        if (entity.SaveChanges() > 0)
                        {
                            tran.Complete();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        return(false);
                    }
                }
            }
        }