示例#1
0
        public bool SetPrediction(dom.Prediction prediction, string username)
        {
            prediction.CreationDate = DateTime.Now;

            if (ExtContext != null && IntContext == null)
            {
                UserHelper uh = new UserHelper();

                var usr = uh.GetUserByUsername(username);
                prediction.User = usr;
                var e = ExtContext.Entry <dom.Prediction>(prediction).Entity;

                e.User = usr;
                ExtContext.Predictions.Attach(e).State = EntityState.Added;

                return(ExtContext.SaveChanges() > 0);
            }
            else
            {
                var uh = new UserHelper(new InMemoryDbContext());

                var us = uh.GetUserByUsername(username);
                prediction.User = us;

                var e = IntContext.Entry <dom.Prediction>(prediction).Entity;

                e.User = us;
                IntContext.Predictions.Attach(e).State = EntityState.Added;
                return(IntContext.SaveChanges() > 0);
            }
        }
示例#2
0
        public bool SetUser(dom.User user)
        {
            var checkuser = GetUserByUsername(user.Username);

            if (checkuser != null && checkuser.Username == user.Username)
            {
                return(false);
            }
            else
            {
                user.CreationDate = DateTime.Now;
                if (ExtContext != null && IntContext == null)
                {
                    ExtContext.Users.Add(user);
                    return(ExtContext.SaveChanges() > 0);
                }
                else
                {
                    IntContext.Users.Add(user);
                    return(IntContext.SaveChanges() > 0);
                }
            }
        }