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

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

            if(entity.QuoteId == 0)
                context.Quotes.AddObject(entity);
            else
                context.Quotes.AttachAsModified(entity);

            context.SaveChanges();

            return entity.QuoteId;
        }
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 FixupQuote(Quote previousValue)
        {
            if (previousValue != null && previousValue.Tags.Contains(this))
            {
                previousValue.Tags.Remove(this);
            }

            if (Quote != null)
            {
                if (!Quote.Tags.Contains(this))
                {
                    Quote.Tags.Add(this);
                }
                if (QuoteId != Quote.QuoteId)
                {
                    QuoteId = Quote.QuoteId;
                }
            }
        }
Beispiel #5
0
        protected virtual QuoteViewModel MapSingle(Quote quote)
        {
            Contract.Requires(quote != null);

            return Mapper.Map<Quote, QuoteViewModel>(quote);
        }