コード例 #1
0
        public IActionResult GetAQuoteInSQL(QuoteViewModel model)
        {
            var watch = Stopwatch.StartNew();

            var Quote = new Quote()
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Email = model.Email,
                PostCode = model.PostCode,
                Created = DateTime.Now
            };

            string quoteNumber = RandomString(8);
            Quote.QuoteNumber = quoteNumber;
            _context.Quotes.Add(Quote);
            _context.SaveChanges();
            var firstCompany = (from c in _context.Quotes select c).FirstOrDefault();
            var kvp = firstCompany.Id;

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            if (ModelState.IsValid)
            {
                ViewBag.Message = "Quote number is: " + quoteNumber + " Time taken: " + elapsedMs + "ms";
            }
            return View();
        }
コード例 #2
0
        public IActionResult GetAQuoteViaGit(QuoteViewModel model)
        {
            var watch = Stopwatch.StartNew();

            string rootedPath = Repository.Init("C:\\temp\\rooted\\path");
            string jsondata = new JavaScriptSerializer().Serialize(model);

            using (var repo = new Repository("C:\\temp\\rooted\\path"))
            {
                // Write content to file system
                System.IO.File.WriteAllText(System.IO.Path.Combine(repo.Info.WorkingDirectory, "output.json"), jsondata);

                // Stage the file
                repo.Stage("output.json");

                // Create the committer's signature and commit
                Signature author = new Signature(model.FirstName, model.Email, DateTime.Now);
                Signature committer = author;

                // Commit to the repository
                try {
                    Commit commit = repo.Commit("Quote committed", author, committer);
                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;

                    if (ModelState.IsValid)
                    {
                        ViewBag.Message = "Quote number is: " + commit.Id + " Time taken: " + elapsedMs + "ms";
                    }
                }
                catch(Exception ex)
                {
                    ViewBag.Message = "Nothing to commit";
                }
            }
            return View();
        }
コード例 #3
0
        public IActionResult RetrieveQuoteSql(string quoteNumber)
        {
            var watch = Stopwatch.StartNew();
            Quote quote = _context.Quotes
                    .Where(b => b.QuoteNumber == quoteNumber)
                    .FirstOrDefault();

            QuoteViewModel viewModel = new QuoteViewModel()
            {
                FirstName = quote.FirstName,
                LastName = quote.LastName,
                Email = quote.Email
            };
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
            ViewBag.Message = "Time taken: " + elapsedMs + " ms";
            return View("DisplayQuoteSql", viewModel);
        }
コード例 #4
0
 public IActionResult DisplayQuoteSql(QuoteViewModel model)
 {
     return View();
 }
コード例 #5
0
        public IActionResult RetrieveQuoteGit(string quoteNumber)
        {
            var watch = Stopwatch.StartNew();
            using (var repo = new Repository("C:\\temp\\rooted\\path"))
            {
                var commit = repo.Lookup<Commit>(quoteNumber);
                var treeEntry = commit["output.json"];

                var blob = (Blob)treeEntry.Target;

                var contentStream = blob.GetContentStream();

                using (var tr = new StreamReader(contentStream, Encoding.UTF8))
                {
                    string content = tr.ReadToEnd();
                    Quote jsondata = new JavaScriptSerializer().Deserialize<Quote>(content);
                    QuoteViewModel viewModel = new QuoteViewModel()
                    {
                        FirstName = jsondata.FirstName,
                        LastName = jsondata.LastName,
                        Email = jsondata.Email
                    };

                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;
                    ViewBag.Message = "Time taken: " + elapsedMs + " ms";
                    return View("DisplayQuoteSql", viewModel);
                }
            }
        }