public IHttpActionResult Login([FromBody] string details) { bool exist = false; float spent = 0; var UP = details.Split('$'); string custID = ""; using (var db = new ComparerModel()) { var cust = db.Customers.ToList(); foreach (Customer x in cust) { if (UP[0] == x.Name && UP[1] == x.Password) { exist = true; spent = x.Spent; custID = x.CardID; } } } if (exist) { return(Ok(custID + "success" + spent.ToString())); } else { return(Ok("failure")); } }
// [HttpPost] public ActionResult Results(ComparerModel model) { /* Set Original document Path */ // JavaScriptSerializer serializer = new JavaScriptSerializer(); ComparerResultModel result = new ComparerResultModel(); if (ModelState.IsValid) { CompareService cs = new CompareService(Session); ComparerResult res = new ComparerResult(); try { res = cs.DoComparison(HttpContext.User, model.GetComparerArguments(UploadPath)); } catch (Exception ex) { Log.Write(TraceEventType.Stop, "Upload Controller, Results | Exception {0}", ex); res.Errors.Add(ex.Message); } result = new ComparerResultModel(res); //return Json(new { success = true, results = serializer.Serialize(new ComparerResultModel(res))}, "application/json"); } else { result.Errors.Add("Input values is not filled or is not valid"); //return Json(new { success = false, message = serializer.Serialize(result) }, "application/json"); } return(View(result)); }
public static void SaveComparer(ComparerModel model) { using (Stream stream = File.Open("ComparedPlayers", FileMode.Create)) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(stream, model); } Debug.Log("Comparer saved"); }
public void AddItem(ComparisonEngine.FromFileToStruct.Product x) { using (var db = new ComparerModel()) { var product = new Product() { Name = x.name, Price = x.price, Date = DateTime.Now, Shop = x.shop, Accept = false }; db.Products.Add(product); db.SaveChanges(); } }
public static void RequestForDatabase(FromFileToStruct.Product x) { using (var db = new ComparerModel()) { Product a = new Product() { Name = x.name, Price = x.price, Shop = x.shop, Date = x.date, Accept = false, ShopID = 0 }; db.Products.Add(a); db.SaveChanges(); } }
public static void UpdateDatabase(List <FromFileToStruct.Product> curr) { bool added = false; using (var db = new ComparerModel()) { List <Price> fullPrices; List <Product> fullProd; fullPrices = db.Prices.ToList(); fullProd = db.Products.ToList(); foreach (FromFileToStruct.Product x in curr) { foreach (Product a in fullProd) { if (a.Name == x.name && a.Shop == x.shop) { foreach (Price q in fullPrices) { if (q.ProductID == a.Id && !added && q.DateT != a.Date) { try { Price newP = new Price() { ProductID = a.Id, PriceD = x.price, DateT = x.date, ShopID = (x.shop == "maxima" ? 0 : (x.shop == "rimi" ? 1 : 3)) }; db.Prices.Add(newP); db.SaveChanges(); added = true; } catch { } } } if (added == false) { Price newP = new Price() { ProductID = a.Id, PriceD = x.price, DateT = x.date, ShopID = (x.shop == "maxima" ? 0: (x.shop == "rimi" ? 1: 3)) }; db.Prices.Add(newP); db.SaveChanges(); added = true; } } } added = false; } } }
public static ComparerModel LoadComparer() { ComparerModel res = null; try { using (Stream stream = File.Open("ComparedPlayers", FileMode.Open)) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); res = (ComparerModel)binaryFormatter.Deserialize(stream); } Debug.Log("Comparer loaded"); } catch { res = new ComparerModel(); } return(res); }
public IHttpActionResult Register([FromBody] string details) { var UP = details.Split('$'); string newID = UP[0].Substring(0, 4) + UP[1].Substring(0, 4) + _random.Next(0, 9999).ToString("D4"); using (var db = new ComparerModel()) { var x = new Customer() { Name = UP[0], Password = UP[1], Spent = 0, CardID = newID }; db.Customers.Add(x); db.SaveChanges(); } return(Ok("success")); }
public IHttpActionResult GenerateDatabase() { using (var db = new ComparerModel()) { DateTime date = DateTime.ParseExact("12/09/17" + " 0:00:00 AM", "MM/dd/yy h:mm:ss tt", CultureInfo.InvariantCulture); var priceX = new Price() { DateT = date, PriceD = 55, ProductID = 55, ShopID = 55 }; db.Prices.Add(priceX); db.SaveChanges(); /*var productA = new Product() { Id = 5, Name = "Jogurtas", Price = 1.57f, Date = DateTime.Now, Accept = false }; * var productB = new Product() { Id = 6, Name = "Batonas", Price = 10.97f, Date = DateTime.Now, Accept = false }; * db.Products.Add(productA); * db.Products.Add(productB); * db.SaveChanges();*/ } return(Ok("success")); }
//class which compares current check product list with one of the databases lists public string CompareResults(List <FromFileToStruct.Product> currentCheck) { infoToShow = ""; List <FromFileToStruct.Product> fullDatabase = new List <FromFileToStruct.Product>(); string list = ""; List <Product> fullData; using (var db = new ComparerModel()) { fullData = db.Products.ToList(); } var maxima = from x in fullData where x.Shop == "maxima" && x.Accept == true select x; var rimi = from x in fullData where x.Shop == "rimi" && x.Accept == true select x; float moneyDifference = 0; if (currentCheck[0].shop == "maxima") { moneyDifference = InfoCollector(1, currentCheck, rimi); } else if (currentCheck[0].shop == "rimi") { moneyDifference = InfoCollector(2, currentCheck, rimi); } else { first = "Shop was not recognized"; } third = write.WriteLast(moneyDifference, infoToShow); return(first + second + third); }
public ActionResult Index(ComparerModel model) { return(View(model)); }
public ActionResult Index() { var model = new ComparerModel(); return(View(model)); }
internal static void CustomerSpentUpdate(float fullCheckPrice) { using (var db = new ComparerModel()) { } }