Beispiel #1
0
        public void Delete(User entity)
        {
            if (context.Users == null)
                throw new InvalidOperationException("Context is not properly initialized. Users is null.");

            //context.Users.Attach(entity);
            context.Users.DeleteObject(entity);
            context.SaveChanges();
        }
Beispiel #2
0
        public int Save(User entity)
        {
            if (context.Users == null)
                throw new InvalidOperationException("Context is not properly initialized. Users is null.");

            if (entity.UserId != 0)
                context.Users.AddObject(entity);
            else
                context.Users.AttachAsModified(entity);

            context.SaveChanges();

            return entity.UserId;
        }
Beispiel #3
0
        public ActionResult Add(QuoteViewModel addQuote)
        {
            Contract.Requires(addQuote != null);
            Contract.Requires(this.ModelState != null);

            if (!ModelState.IsValid || String.IsNullOrWhiteSpace(addQuote.PosterIpAddress))
                return View();

            var user = users.GetByIpAddress(addQuote.PosterIpAddress);

            if(user == null) {
                user = new User();
                user.IpAddress = addQuote.PosterIpAddress;
                user.LastSeen = DateTime.Now;
            }

            var quote = new Quote(addQuote.Text, user);
            quotes.Save(quote);

            return RedirectToAction("Index");
        }
Beispiel #4
0
        private void FixupUser(User previousValue)
        {
            if (previousValue != null && previousValue.Quotes.Contains(this))
            {
                previousValue.Quotes.Remove(this);
            }

            if (User != null)
            {
                if (!User.Quotes.Contains(this))
                {
                    User.Quotes.Add(this);
                }
                if (PosterId != User.UserId)
                {
                    PosterId = User.UserId;
                }
            }
        }
Beispiel #5
0
 public Quote(string text, User user)
     : this()
 {
     Text = text;
     User = user;
 }
Beispiel #6
0
        private void FixupUser(User previousValue)
        {
            if (previousValue != null && previousValue.Tags.Contains(this))
            {
                previousValue.Tags.Remove(this);
            }

            if (User != null)
            {
                if (!User.Tags.Contains(this))
                {
                    User.Tags.Add(this);
                }
                if (TaggerId != User.UserId)
                {
                    TaggerId = User.UserId;
                }
            }
        }