Example #1
0
        // Full summary of Quote/Property/Location
        public ActionResult QuoteSummary(int?quoteId)
        {
            if (!quoteId.HasValue)
            {
                try
                {
                    quoteId = (int)Session["quoteId"];
                }

                catch
                {
                    // TODO: redirect
                    return(RedirectToAction("GetStarted", "Quotes"));
                }
            }

            else
            {
                Session["quoteId"] = quoteId;
            }

            // TODO: do we have a User?
            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                Quote q = qe.IncludeInQuotes("Property.Location.Homeowner.User").Where(qq => qq.Id == quoteId).FirstOrDefault();
                return(View(q));
            }
        }
        public ActionResult QuoteDetails()
        {
            User         user      = Session["User"] as User;
            List <Quote> quoteList = new List <Quote>();

            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                quoteList.AddRange(qe.IncludeInQuotes("Property.Location.Homeowner.User")
                                   .Where(q => q.Property.Location.Homeowner.UserId == user.Id));
                return(View(quoteList));
            }
        }
Example #3
0
        public ActionResult MyPolicies()
        {
            User          user     = Session["User"] as User;
            List <Policy> policies = new List <Policy>();

            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                Homeowner ho = qe.Homeowners.FirstOrDefault(h => h.UserId == user.Id);
                if (ho == null)
                {
                    return(View(policies));
                }
                policies.AddRange(qe.IncludeInPolicies("Quote.Property.Location.Homeowner.User")
                                  .Where(p => p.Quote.Property.Location.Homeowner.UserId == ho.UserId));
                return(View(policies));
            }
        }
Example #4
0
        public ActionResult QuoteDetails()
        {
            User         user      = Session["User"] as User;
            List <Quote> quoteList = new List <Quote>();

            //List<Policy> policyList = new List<Policy>();
            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                Homeowner ho = qe.Homeowners.FirstOrDefault(h => h.UserId == user.Id);
                quoteList.AddRange(qe.IncludeInQuotes("Property.Location.Homeowner.User")
                                   .Where(q => q.Property.Location.Homeowner.UserId == user.Id));
                //policyList.AddRange(qe.IncludeInPolicies("Quote.Property.Location.Homeowner.User")
                //    .Where(p => p.Quote.Property.Location.Homeowner.UserId == ho.UserId));
                //var quotesWithPolicy = quoteList.Where(q => policyList.Any(p => p.QuoteId == q.Id));
                //var quotesWithoutPolicy = quoteList.Except(quotesWithPolicy);
                return(View(quoteList));
                //return View(quotesWithoutPolicy);
            }
        }
Example #5
0
        public ActionResult Confirmation()
        {
            int policyId;

            try
            {
                policyId = (int)Session["policyId"];
            }

            catch
            {
                return(RedirectToAction("GetStarted", "Quotes"));
            }
            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                Policy p = qe.Policies.FirstOrDefault(pp => pp.Id == policyId);
                return(View(p));
            }
        }
        public ActionResult LoginUser(User user)
        {
            if (!ModelState.IsValid)
            {
                return(View("LoginUser"));
            }

            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                User existing = qe.Users.FirstOrDefault(u => u.Password == user.Password &&
                                                        u.Username == user.Username);

                if (existing == null)
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    return(View("LoginUser", user));
                }

                return(RedirectUser(existing));
            }
        }
        // Full summary of Quote/Property/Location
        public ActionResult QuoteSummary(int?quoteId)
        {
            if (!quoteId.HasValue)
            {
                try
                {
                    quoteId = (int)Session["quoteId"];
                }

                catch
                {
                    // TODO: redirect
                    return(RedirectToAction("GetStarted", "Quotes"));
                }
            }

            else
            {
                Session["quoteId"] = quoteId;
            }

            // TODO: do we have a User?
            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                Quote q = qe.IncludeInQuotes("Property.Location.Homeowner.User").Where(qq => qq.Id == quoteId).FirstOrDefault();
                // TODO: is q null?

                //Added this section in order to stop the user from being able to buy same quote multiple times
                List <Policy> policies = new List <Policy>();
                User          user     = Session["User"] as User;
                Homeowner     ho       = qe.Homeowners.FirstOrDefault(h => h.UserId == user.Id);
                policies.AddRange(qe.IncludeInPolicies("Quote.Property.Location.Homeowner.User")
                                  .Where(p => p.Quote.Property.Location.Homeowner.UserId == ho.UserId && p.QuoteId == q.Id));
                bool isPolicyExist = policies.Count > 0;
                Tuple <Quote, bool> returningParameters = new Tuple <Quote, bool>(q, isPolicyExist);              //Tuple used for multiple returns
                return(View(returningParameters));

                //return View(q); This not needed anymore, q returned in line 55 via Tuple
            }
        }
Example #8
0
        public ActionResult SaveQuote()
        {
            Quote     quote     = Session["Quote"] as Quote;
            Property  property  = Session["Property"] as Property;
            Location  location  = Session["Location"] as Location;
            Homeowner homeowner = Session["Homeowner"] as Homeowner;
            User      user      = Session["User"] as User;

            quote.Property     = property;
            property.Location  = location;
            location.Homeowner = homeowner;

            homeowner.UserId = user.Id;
            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                qe.AddQuote(quote);
                qe.SaveChanges();
            }

            Session.Clear();
            Session["User"] = user;
            return(RedirectToAction("QuoteDetails"));
        }
        public ActionResult NewUser(NewUser newUser)
        {
            if (!ModelState.IsValid)
            {
                return(View("NewUser", newUser));
            }

            using (IQuotesEntity qe = QuoteSource.CreateQuotesEntity())
            {
                User u = qe.Users.FirstOrDefault(model => model.Username == newUser.Username);

                if (u != null)
                {
                    ModelState.AddModelError("", "This username already exists.");
                    return(View("NewUser", newUser));
                }

                User user = new User(newUser);
                qe.AddUser(user);
                qe.SaveChanges();
                return(RedirectUser(user));
            };
        }