using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Web.Helpers; using System.Web.Http; using System.Web.UI; using Microsoft.Ajax.Utilities; using System.Web.Script.Serialization; using ReinkeAppsApi.Models; using System.Linq; namespace ReinkeAppsApi.Controllers { [RequireHttps] [Route("v1/quote")] public class QuoteV1Controller : ApiController { public IEnumerable Get() { return new string[] { "1032: I\'m putting myself to the fullest possible use, which is all any conscious entity can ever hope to do." }; } //[Authorize] [BasicAuthentication] public HttpResponseMessage Post(object obj) { string stringBody = obj.ToString(); if (stringBody.Contains("qpQuoteData")) { JavaScriptSerializer os = new JavaScriptSerializer(); QuotePackageV1 qpv1 = os.Deserialize(stringBody); qpv1.qpHistory.AccessDateTime = DateTime.Now; ProcessQuote(qpv1); return Request.CreateResponse(HttpStatusCode.OK); } return Request.CreateResponse(HttpStatusCode.BadRequest); } private void ProcessQuote(QuotePackageV1 quotepkg) { LogQuote(quotepkg.qpHistory); } private void LogQuote(QuoteHistoryV1 qpHistory) { try { using (QuotesDataContext db = new QuotesDataContext()) { QuoteHistory qh = new QuoteHistory { qhAccessDateTime = qpHistory.AccessDateTime, qhComputerName = qpHistory.ComputerName, qhFileName = qpHistory.FileName, qhIpAddress = qpHistory.IpAddress, qhMapicsDealerNumber = qpHistory.MapicsDealerNumber }; db.QuoteHistories.InsertOnSubmit(qh); db.SubmitChanges(); } } catch (Exception ex) { throw; } } public bool QuoteExists(QuoteV1 quote) { using (QuotesDataContext db = new QuotesDataContext()) { var Result = from a in db.DealerQuotes where a.dqDealerId == quote.DealerId & a.dqSubmitted == false & a.dqFileName == quote.FileName select a; if (Result.Any()) { return true; } } return false; } private void InsertQuote(QuoteV1 quote, QuoteDataV1 quotaData) { using (QuotesDataContext db = new QuotesDataContext()) { } } private void UpdateQuote(QuoteDataV1 quoteData) { } } }