daily pastebin goal
68%
SHARE
TWEET

QuoteControllerV1

CryptoJones Oct 26th, 2016 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.Net.Http;
  5. using System.Web.Helpers;
  6. using System.Web.Http;
  7. using System.Web.UI;
  8. using Microsoft.Ajax.Utilities;
  9. using System.Web.Script.Serialization;
  10. using ReinkeAppsApi.Models;
  11. using System.Linq;
  12.  
  13. namespace ReinkeAppsApi.Controllers
  14. {
  15.     [RequireHttps]
  16.     [Route("v1/quote")]
  17.     public class QuoteV1Controller : ApiController
  18.     {
  19.         public IEnumerable<string> Get()
  20.         {
  21.             return new string[]
  22.             {
  23.                 "1032: I\'m putting myself to the fullest possible use, which is all any conscious entity can ever hope to do."
  24.             };
  25.         }
  26.  
  27.         //[Authorize]
  28.         [BasicAuthentication]
  29.         public HttpResponseMessage Post(object obj)
  30.         {
  31.             string stringBody = obj.ToString();
  32.             if (stringBody.Contains("qpQuoteData"))
  33.             {
  34.                 JavaScriptSerializer os = new JavaScriptSerializer();
  35.  
  36.                 QuotePackageV1 qpv1 = os.Deserialize<QuotePackageV1>(stringBody);
  37.                 qpv1.qpHistory.AccessDateTime = DateTime.Now;
  38.                 ProcessQuote(qpv1);
  39.                 return Request.CreateResponse(HttpStatusCode.OK);
  40.             }
  41.  
  42.             return Request.CreateResponse(HttpStatusCode.BadRequest);
  43.  
  44.         }
  45.  
  46.         private void ProcessQuote(QuotePackageV1 quotepkg)
  47.         {
  48.  
  49.             LogQuote(quotepkg.qpHistory);
  50.  
  51.         }
  52.  
  53.         private void LogQuote(QuoteHistoryV1 qpHistory)
  54.         {
  55.             try
  56.             {
  57.                 using (QuotesDataContext db = new QuotesDataContext())
  58.                 {
  59.                     QuoteHistory qh = new QuoteHistory
  60.                     {
  61.                         qhAccessDateTime = qpHistory.AccessDateTime,
  62.                         qhComputerName = qpHistory.ComputerName,
  63.                         qhFileName = qpHistory.FileName,
  64.                         qhIpAddress = qpHistory.IpAddress,
  65.                         qhMapicsDealerNumber = qpHistory.MapicsDealerNumber
  66.                     };
  67.  
  68.                     db.QuoteHistories.InsertOnSubmit(qh);
  69.                     db.SubmitChanges();
  70.                 }
  71.             }
  72.             catch (Exception ex)
  73.             {
  74.                
  75.  
  76.                 throw;
  77.             }
  78.            
  79.         }
  80.  
  81.         public bool QuoteExists(QuoteV1 quote)
  82.         {
  83.             using (QuotesDataContext db = new QuotesDataContext())
  84.             {
  85.                 var Result = from a in db.DealerQuotes
  86.                              where a.dqDealerId == quote.DealerId
  87.                              & a.dqSubmitted == false
  88.                              & a.dqFileName == quote.FileName
  89.                              select a;
  90.  
  91.                 if (Result.Any())
  92.                 {
  93.                     return true;
  94.                 }
  95.  
  96.             }
  97.             return false;
  98.         }
  99.  
  100.         private void InsertQuote(QuoteV1 quote, QuoteDataV1 quotaData)
  101.         {
  102.             using (QuotesDataContext db = new QuotesDataContext())
  103.             {
  104.             }
  105.         }
  106.  
  107.         private void UpdateQuote(QuoteDataV1 quoteData)
  108.         {
  109.         }
  110.  
  111.  
  112. }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top