public ActionResult Save(ItemQuality item) { using (var db = new LifeIsFeudalDb()) { if (item.Id == 0) { db.ItemQualities.Add(item); } else { var existing = db.ItemQualities.ToList().FirstOrDefault(x => x.Id == item.Id); existing.BuyActive = item.BuyActive; existing.SellActive = item.SellActive; existing.Item_Id = item.Item_Id; existing.ItemQualityType_Id = item.ItemQualityType_Id; existing.Free = item.Free; existing.OverridePrice = item.OverridePrice; db.Entry(existing).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); var ret = new { buy_active = item.BuyActive, id = item.Id, Item_id = item.Item_Id, ItemQualityType_id = item.ItemQualityType_Id, sell_active = item.SellActive, created_at = item.Created, free = item.Free, overridePrice = item.OverridePrice }; return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public static void SendEmailMessage(string subject, string body) { try { using (var mail = new MailMessage()) using (var db = new LifeIsFeudalDb()) { _emailTo = db.Configurations.FirstOrDefault(x => x.Key == "Email").Value; mail.From = new MailAddress(_emailFrom); mail.To.Add(_emailTo); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; // Can set to false, if you are sending pure text. using (SmtpClient smtp = new SmtpClient()) { smtp.Credentials = new NetworkCredential(_emailFrom, _password); //smtp.Host = "localhost"; //smtp.EnableSsl = enableSSL; smtp.Send(mail); } } } catch (Exception ex) { return; } }
public ActionResult Save(OrderForm product) { using (var db = new LifeIsFeudalDb()) { try { db.OrderForms.Add(product); db.SaveChanges(); product.OrderNumber = product.Id.ToString().PadLeft(5, '0'); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); var ret = new { OrderNumber = product.OrderNumber, PlayerName = product.PlayerName }; return(Json(ret)); } catch (Exception ie) { var e = ie; return(Json(ie)); } } }
public ActionResult SendOrder(OrderForm order, List <OrderFormProduct> products) { string htmlBody;// = htmlMessage.CreateHtmlHeader(order); using (var db = new LifeIsFeudalDb()) { products.ForEach(x => { x.ItemQuality = db.ItemQualities.FirstOrDefault(y => x.ItemQuality_Id == y.Id); }); order.Products = products; htmlBody = htmlMessage.CreateEmailHtml(order); //var itemsSelling = products.Where(x => x.Selling).ToList(); //var itemsBuying = products.Where(x => !x.Selling).ToList(); //if(itemsSelling.Count > 0) //{ // htmlBody += "</br><p>Selling</p>"; // htmlBody += htmlMessage.CreateTable(itemsSelling); //} //if(itemsBuying.Count > 0) //{ // htmlBody += "</br></br><p>Buying</p>"; // htmlBody += htmlMessage.CreateTable(itemsBuying); //} SendEmail.SendEmailMessage($"Player Order: {order.PlayerName} Order Number: {order.Id.ToString().PadLeft(5,'0')}", htmlBody); return(Json(new { success = true, data = new { } })); } }
public ActionResult All() { using (var db = new LifeIsFeudalDb()) { var ret = db.SubCategories.ToList(); return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult SaveOrderFormProduct(OrderFormProduct product) { using (var db = new LifeIsFeudalDb()) { db.OrderFormProducts.Add(product); db.SaveChanges(); return(Json(product, JsonRequestBehavior.AllowGet)); } }
public ActionResult Save(Configuration config) { using (var db = new LifeIsFeudalDb()) { db.Entry(config).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Json(config)); } }
public ActionResult All() { using (var db = new LifeIsFeudalDb()) { var ret = db.Categories.ToList().Select(x => new { id = x.Id, name = x.Name }); return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetSubCategoriesById(long id) { using (var db = new LifeIsFeudalDb()) { var ret = db.Items.Where(x => x.Category_Id == id).Select(x => new { id = x.SubCategory.Id, name = x.SubCategory.Name }).ToList().Distinct(); return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult All() { using (var db = new LifeIsFeudalDb()) { var ret = db.Configurations.ToList().Select(x => new { id = x.Id, key = x.Key, value = x.Value }); return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetItemsById(long catId, long subId) { using (var db = new LifeIsFeudalDb()) { var ret = db.Items.Where(x => x.SubCategory_Id == subId && x.Category_Id == catId).ToList() .Select(x => new { id = x.Id, name = x.Name, price = x.Price }); return(Json(ret, JsonRequestBehavior.AllowGet)); }; }
public ActionResult GetItemQualitiesById(long id) { using (var db = new LifeIsFeudalDb()) { var ret = db.ItemQualities.Where(x => x.Item_Id == id).ToList().Select(x => new { buy_active = x.BuyActive, id = x.Id, Item_id = x.Item_Id, ItemQualityType_id = x.ItemQualityType_Id, sell_active = x.SellActive, created_at = x.Created });; return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult All() { using (var db = new LifeIsFeudalDb()) { var a = db.Items.ToList().Select(x => new { created_at = x.Created, id = x.Id, name = x.Name, price = x.Price, sub_category = x.SubCategory_Id, category_id = x.Category_Id }).OrderBy(x => x.category_id).OrderBy(x => x.sub_category).OrderBy(x => x.name);; return(Json(a, JsonRequestBehavior.AllowGet));; } }
// GET: ItemQualityType public ActionResult All() { using (var db = new LifeIsFeudalDb()) { var ret = db.ItemQualityTypes.ToList().Select(x => new { id = x.Id, name = x.Name, sell_multiplier = x.SellMultiplier, buy_multiplier = x.BuyMultiplier, updated_at = x.Updated }); return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetItemQualities(long id) { using (var db = new LifeIsFeudalDb()) { var items = db.ItemQualities.ToList().Where(x => x.Id == id).Select(y => new { buy_active = y.BuyActive, id = y.Id, Item_id = y.Item_Id, ItemQualityType_id = y.ItemQualityType_Id, sell_active = y.SellActive, overridePrice = y.OverridePrice, free = y.Free, created_at = y.Created }); return(Json(items, JsonRequestBehavior.AllowGet)); } }
// GET: ItemQuality public ActionResult All() { using (var db = new LifeIsFeudalDb()) { var ret = db.ItemQualities.ToList().Select(x => new { x.Id, x.Item_Id, x.SellActive, x.ItemQualityType_Id, x.Free, x.OverridePrice, x.BuyActive, x.Created }); return(Json(ret, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetItemQualityById(long id) { using (var db = new LifeIsFeudalDb()) { var ret = db.ItemQualities.FirstOrDefault(x => x.Id == id); var item = new { buy_active = ret.BuyActive, id = ret.Id, Item_id = ret.Item_Id, ItemQualityType_id = ret.ItemQualityType_Id, sell_active = ret.SellActive, overridePrice = ret.OverridePrice, free = ret.Free, created_at = ret.Created }; return(Json(item, JsonRequestBehavior.AllowGet)); } //var a = LifeIsFeudalApi.GetItemQuality(id); }
public ActionResult SaveItem(Item item) { using (var db = new LifeIsFeudalDb()) { if (item.Id == 0) { db.Items.Add(item); return(Json(item)); } else { var findExisting = db.Items.ToList().FirstOrDefault(x => x.Id == item.Id); findExisting.Name = item.Name; findExisting.Price = item.Price; findExisting.SubCategory_Id = item.SubCategory_Id; findExisting.Category_Id = item.Category_Id; db.Entry(findExisting).State = System.Data.Entity.EntityState.Modified; return(Json(item)); } } }
public static void ReadFile(string filePath) { using (var wb = new XLWorkbook(filePath)) using (var db = new LifeIsFeudalDb()) { var qualities = db.ItemQualityTypes.ToList(); var ws = wb.Worksheet(1); List <Category> _categoriesReadyToSave = new List <Category>(); List <SubCategory> _subCategoriesReadyToSave = new List <SubCategory>(); List <Item> _itemsReadyToSave = new List <Item>(); Category cat = new Category(); SubCategory _sub = new SubCategory(); foreach (IXLRow row in ws.RowsUsed()) { if (row.RowNumber() >= 5) { try { var name = row.Cell("A").Value.ToString(); var buy = row.Cell("C").Value.ToString(); var sell = row.Cell("D").Value.ToString(); var hidden = row.IsHidden; if (name == "Builder's Corner") { Console.WriteLine("----======="); } if (row.IsHidden) { continue; } if (string.IsNullOrEmpty(buy) && string.IsNullOrEmpty(sell) && name != "Hand and a Half Swords") { if (!string.IsNullOrEmpty(name)) { _sub = db.SubCategories.ToList().FirstOrDefault(x => x.Name == "General Goods"); //Leave and continue cat = new Category { Name = name, Created = DateTime.Now }; _categoriesReadyToSave.Add(cat); Console.WriteLine($"Category: {name}"); } } else { if (string.IsNullOrEmpty(sell)) { _sub = new SubCategory { Name = name }; _subCategoriesReadyToSave.Add(_sub); Console.WriteLine($"SubCategory: {name}"); } else { var setFree = false; if (sell.Equals("Free")) { setFree = true; sell = "0"; } Item _item = new Item { Name = name, Category = cat, SubCategory = _sub, Price = Convert.ToInt32(StripCharacters(sell)), Created = DateTime.Now }; foreach (var quality in qualities) { _item.Qualities.Add(new ItemQuality { Item = _item, Free = setFree, BuyActive = true, SellActive = true, ItemQualityType = quality, ItemQualityType_Id = quality.Id, Created = DateTime.Now }); } _itemsReadyToSave.Add(_item); Console.WriteLine($"Item: {name}"); } } } catch (Exception e) { if (e.Message.Contains("base materials")) { continue; } Console.WriteLine(e); } } } db.Categories.AddRange(_categoriesReadyToSave); db.SubCategories.AddRange(_subCategoriesReadyToSave); db.Items.AddRange(_itemsReadyToSave); db.SaveChanges(); } }