public Models.Quote_DTO Get()
        {
            Models.Quote q    = QuoteFetcher.GetQuote();
            var          qdto = new Models.Quote_DTO(q);

            return(qdto);
        }
Ejemplo n.º 2
0
        // GET: Home
        public ActionResult Index()
        {
            HttpClient          Client   = new HttpClient();
            HttpResponseMessage response = Client.GetAsync("http://localhost:49496/api/jarus/GetQuotes").Result;

            response.EnsureSuccessStatusCode();
            Models.Quote quote = response.Content.ReadAsAsync <Models.Quote>().Result;
            ViewBag.Title = "Quotes";
            return(View(quote));
        }
Ejemplo n.º 3
0
        public IHttpActionResult CreateQuote(Models.Quote quote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _db.InsertOneAsync(quote);
            return(Created(new Uri(Request.RequestUri + "/" + quote.Id), quote));
        }
        public ActionResult Create(Models.Quote quote)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            _db.InsertOneAsync(quote);

            return(RedirectToAction("Index", "Quote", null));
        }
        private void SeedDb()
        {
            this.TruncateForumsTable();
            this.TruncatePostsTable();
            this.TruncateQuotesTable();
            this.TruncateUsersTable();

            var post = new Models.Post {
                Id = TestsConstants.TestId
            };

            this.dbService.DbContext.Posts.Add(post);
            this.dbService.DbContext.SaveChanges();

            var reply = new Models.Reply {
                Id = TestsConstants.TestId2, Post = post, PostId = post.Id
            };

            this.dbService.DbContext.Replies.Add(reply);
            this.dbService.DbContext.SaveChanges();

            var author = new ForumUser {
                Id = TestsConstants.TestId, UserName = TestsConstants.TestUsername1
            };
            var reciever = new ForumUser {
                Id = TestsConstants.TestId1, UserName = TestsConstants.TestUsername2
            };

            this.dbService.DbContext.Users.Add(author);
            this.dbService.DbContext.Users.Add(reciever);
            this.dbService.DbContext.SaveChanges();

            var firstQuote = new Models.Quote {
                Id = TestsConstants.TestId1, Author = author, AuthorId = author.Id, Reply = reply, ReplyId = reply.Id
            };

            this.dbService.DbContext.Quotes.Add(firstQuote);
            this.dbService.DbContext.SaveChanges();

            for (int i = 0; i < 5; i++)
            {
                var quote = new Models.Quote {
                    Id = Guid.NewGuid().ToString(), Author = author, AuthorId = author.Id, Reply = reply, ReplyId = reply.Id
                };

                this.dbService.DbContext.Quotes.Add(quote);
                this.dbService.DbContext.SaveChanges();
            }
        }
        public ActionResult Edit(Models.Quote quote)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            _db.FindOneAndUpdateAsync(Builders <Models.Quote>
                                      .Filter
                                      .Eq("Id", quote.Id),
                                      Builders <Models.Quote>
                                      .Update
                                      .Set("Text", quote.Text)
                                      .Set("Author", quote.Author));

            return(RedirectToAction("Index", "Quote", null));
        }
Ejemplo n.º 7
0
        public IHttpActionResult EditQuote(Models.Quote quote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!isExistQuote(quote.Id))
            {
                return(NotFound());
            }

            _db.FindOneAndUpdateAsync(Builders <Models.Quote> .Filter.Eq("Id", quote.Id),
                                      Builders <Models.Quote> .Update.Set("Text", quote.Text).Set("Author", quote.Author));

            return(Ok(_db.Find(new BsonDocument()).ToList().SingleOrDefault(q => q.Id.Equals(quote.Id))));
        }
Ejemplo n.º 8
0
        public IActionResult Create(string name, string content)
        {
            Models.Quote quote = new Models.Quote(name, content);

            TryValidateModel(quote);

            if (ModelState.IsValid)
            {
                string query = $"INSERT INTO users (name, quote,created_at) VALUES ('{quote.name}', '{quote.content}',NOW());";
                DbConnector.Execute(query);
                return(RedirectToAction("QuotesSplash"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
    {//http://json2csharp.com/
        public static Models.Quote GetQuote()
        {
            string json;

            Models.Quote q;
            json = GetProductAsync("https://talaikis.com/api/quotes/random/").Result;
            if (SeemsLikeValidReply(json))
            {
                q = new Models.Quote(json);
            }
            else
            {
                q        = new Models.Quote();
                q.quote  = json;
                q.author = json;
            }
            return(q);
        }
Ejemplo n.º 10
0
 public void Put(int Id, [FromBody] Models.Quote quote)
 {
     QuoteList[Id] = quote;
 }
Ejemplo n.º 11
0
 public void Post([FromBody] Models.Quote quote)
 {
     QuoteList.Add(quote);
 }
Ejemplo n.º 12
0
        public static decimal GetPriceQuote(Models.Quote quote)
        {
            //From an insurance (and maintenance) standpoint, the following logic could be greatly improved
            //but it's what was called for. We'll go along with it for demo purposes.
            //We've also separate conditions that could be combined to ease future alterations.

            decimal price = 0m;

            if (quote.CoverageID == 1 || quote.CoverageID == 3) //lowest liability coverage
            {
                price += 50m;
            }
            else if (quote.CoverageID == 2 || quote.CoverageID == 4) //higher liability coverage
            {
                price += 75m;
            }

            using (var db = new Models.InsuranceQuoteDBEntities())
            {
                //////////////////User's Age//////////////////////
                DateTime dob;
                if (Visitor.IsVisitor(quote.CustomerID))
                {
                    //this query will only contain one element since (DrivingHistoryID) is a key
                    dob = (DateTime)db.VisitorSessions.Where(x => x.DrivingHistoryId == quote.DrivingHistoryID).First().DateOfBirth;
                }
                else
                {
                    dob = (DateTime)db.Customers.Find(quote.CustomerID).DateOfBirth;
                }
                double ageYears = ((DateTime)quote.DateIssued - dob).TotalDays / 365.25;
                //age could differ from legal age by approx 8 hours depending on where leap year lands
                if (ageYears < 18)
                {
                    price += 100m;
                }
                else if (ageYears < 25)
                {
                    price += 25m;
                }
                else if (ageYears > 100)
                {
                    price += 100m;
                }

                ////////////////////Model Year//////////////////
                var autoModel  = db.AutoModels.Find(quote.AutoModelID);
                var autoMake   = db.AutoMakes.Find(autoModel.AutoMakeID);
                var autoOption = db.AutoOptions.Find(quote.AutoOptionID);
                if (autoModel.ModelYear < 2000)
                {
                    price += 25m;
                }
                else if (autoModel.ModelYear > 2015)
                {
                    price += 25m;
                }

                //The following logic approximates the logic that was called for but works better for
                //all makes and models and incorporates risk factors based on horsepower, curb weight, and MSRP (retail price)
                ////////////////////Auto (vehicle) Risk Factors/////////////////////
                switch (autoMake.MakeRiskLevelID)
                {
                case 1:     //low, do nothing
                    break;

                case 2:     //moderate
                    price += 12.50m;
                    break;

                case 3:     //high
                    price += 25m;
                    break;

                default:     //higher, doesn't currently exist
                    price += 50m;
                    break;
                }
                switch (autoModel.ModelRiskLevelID)
                {
                case 1:     //low, do nothing
                    break;

                case 2:     //moderate
                    price += 12.50m;
                    break;

                case 3:     //high
                    price += 25m;
                    break;

                default:     //higher, doesn't currently exist
                    price += 50m;
                    break;
                }
                if (autoOption != null) //option package is not required
                {
                    switch (autoOption.OptionRiskLevelId)
                    {
                    case null:
                    case 1:     //low, do nothing
                        break;

                    case 2:     //moderate
                        price += 10m;
                        break;

                    case 3:     //high
                        price += 20m;
                        break;

                    case 4:     //very high
                        price += 30m;
                        break;

                    case 5:     //extreme
                        price += 40m;
                        break;

                    default:     //higher, doesn't currently exist
                        price += 50m;
                        break;
                    }
                }

                ///////////////////Driving History/////////////////////////
                var cdh = db.CustomerDrivingHistories.Find(quote.DrivingHistoryID);
                price += (decimal)cdh.NumSpeedingTickets * 10m; //increase $10 for each speeding ticket
                if (cdh.NumDUIs > 0)
                {
                    price *= 1.25m;                  //increase by 25%
                }
            }

            //////////////////Full Coverage Options////////////////////
            if (quote.CoverageID == 3)      //high deductible
            {
                price *= 1.25m;             //increase by 25%
            }
            else if (quote.CoverageID == 4) //low deductible
            {
                price *= 1.5m;
            }

            return(price);
        }