public ActionResult Create(Order entity) { GetViewBag_Session(); if (ModelState.IsValid) { entity.CreateDate = DateTime.Now; var model = new OrderDAO().Insert(entity); // Written log var logEntity = new Log_Admin(); logEntity.createBy = ViewBag.Name_Session; logEntity.time = DateTime.Now; logEntity.action = "Thêm mới đơn hàng " + "<a href = \"/Admin/Order/Update/" + entity.ID + "\">" + entity.ID + "</a>"; logEntity.description = ViewBag.Name_Session + " thêm mới đơn hàng vào hệ thống"; var wlog = new Log_AdminDAO().InsertLog(logEntity); if (model > 0) { return(RedirectToAction("Index", "Order")); } else { ModelState.AddModelError("", "Thêm thành công đơn hàng vào hệ thống"); } } GetProduct(); return(View("Create")); }
public ActionResult <string> Index(OrderHelper helper) { string retVal = ""; try { CustomerDAO uDao = new CustomerDAO(_ctx); Customer OrderOwner = uDao.GetByEmail(helper.email); OrderDAO cDAO = new OrderDAO(_ctx); int orderId = cDAO.AddOrder(OrderOwner.Id, helper.selections); foreach (OrderSelectionHelper order in helper.selections) { if (orderId > 0 || order.item.QtyOnHand == 0) { retVal = "Order " + orderId + " created! Goods Backordered"; } else if (orderId > 0 || order.item.QtyOnHand > 0) { retVal = "Order " + orderId + " created!"; } else { retVal = "Order not created"; } } } catch (Exception ex) { retVal = "Order not created " + ex.Message; } return(retVal); }
public void RemoveOrder_ShouldDeleteOrderWithoutDeletingProductsOrCustomers() { // Arrange ProductDAO productDAO = new ProductDAO(); Product product1 = new Product("Fanta", 2.5m); Product product2 = new Product("Cola", 2.2m); CustomerDAO customerDAO = new CustomerDAO(); customerDAO.AddCustomer(new Customer("Jan Jansenss", "Straat 123")); Customer customer = customerDAO.GetCustomer(1); OrderDAO orderDAO = new OrderDAO(); DateTime dateTime = new DateTime(2020, 12, 05, 05, 05, 05); Order order = new Order(dateTime); order.SetCustomer(customer); order.AddProduct(product1, 1); order.AddProduct(product2, 3); order.IsPayed = true; orderDAO.AddOrder(order); // Act orderDAO.RemoveOrder(1); // Assert orderDAO.GetOrder(1).Should().BeNull(); productDAO.GetProduct(1).Should().NotBeNull(); productDAO.GetProduct(2).Should().NotBeNull(); customerDAO.GetCustomer(1).Should().NotBeNull(); }
private void cancelStatus() { string orderid = Request.Params["order_id"]; OrderDAO.updateStatus(orderid); sendResponse("success"); }
public List <OrderId> getAllInvalidOrders() { OrderDAO datalayer = new OrderDAO(); List <OrderId> orderNumbers = datalayer.getAllInvalidOrders(); return(orderNumbers); }
public void PlaceOrder() { var orderRepo = RepositoryManager.OrderRepo(); var orderdetailRepo = RepositoryManager.OrderDetailRepo(); var odItems = orderdetailRepo.GetItems(); var amount = odItems.Sum(c => c.Price * c.Quantity); var orderItem = new OrderDAO() { Comment = Comment, Name = Name, Date = Date, Phone = Phone, PickupTime = SelectedTime, IsOrderComplete = true, Amount = amount, StoreId = StoreId, }; //Save Order Item orderRepo.SaveItem(orderItem); //Update Order Detail with latest order id; for (int i = 0; i < odItems.Count(); i++) { odItems[i].OrderId = orderItem.ID; } //save order details with new order id; orderdetailRepo.SaveItems(odItems); }
private void button13_Click(object sender, EventArgs e) { List <Order> ord = OrderDAO.orderlist(); dataGridView4.DataSource = null; dataGridView4.DataSource = ord; }
public JsonResult EditOrder(string strOrder) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var order = serializer.Deserialize <Order>(strOrder); var dao = new OrderDAO(); var orderold = dao.GetDetailById((int)order.ID); if (order.Status == 2 && order.Status > orderold.Status) { var res = dao.DeliveryOrder(order); return(Json(new { mes = res })); } else if (order.Status == 2 && order.Status == orderold.Status) { var res = dao.ChangeStatus(order); return(Json(new { mes = res })); } else if (order.Status < orderold.Status) { var res = dao.CancelOrder(order); return(Json(new { mes = res })); } else { var res = dao.ChangeStatus(order); return(Json(new { mes = res })); } }
public void AddOrder_ShouldAddOrderWithCustomer() { // Arrange CustomerDAO customerDAO = new CustomerDAO(); customerDAO.AddCustomer(new Customer("Jan Jansenss", "Straat 123")); Customer customer = customerDAO.GetCustomer(1); OrderDAO orderDAO = new OrderDAO(); DateTime dateTime = new DateTime(2020, 12, 05, 05, 05, 05); Order order = new Order(dateTime); order.IsPayed = true; order.SetCustomer(customer); // Act orderDAO.AddOrder(order); // Assert Order orderInDb = orderDAO.GetOrder(1); orderInDb.Should().BeOfType <Order>(); orderInDb.DateTime.Should().Be(dateTime); orderInDb.IsPayed.Should().Be(true); orderInDb.PriceAlreadyPayed.Should().Be(0); orderInDb.Id.Should().Be(1); orderInDb.Customer.Should().BeEquivalentTo(customer); }
internal static void PlaceOrder(List <ProductInStock> ShoppingCart, Billing BillingInfo, Shipping ShippingInfo, Customer CurrentCustomer, Location CurrentLocation, P1Context _context) { DateTime now = System.DateTime.Now; var DB = _context; Order Order = new Order { CustomerID = CurrentCustomer.CustomerID, LocationID = CurrentLocation.LocationID, BillingID = BillingInfo.BillingID, ShippingID = ShippingInfo.ShippingID, OrderTime = now.ToString() }; OrderDAO.AddOrders(Order, DB); LocationProductsDAO.LoadLocationProductsList(DB); foreach (ProductInStock p in ShoppingCart) { OrderProducts OP = new OrderProducts { OrderID = Order.OrderID, ProductID = p.ProductID, Quantity = p.Quantity }; OrderProductsDAO.AddOrderProducts(OP, DB); LocationProducts LP = DB.LocationProductsList.Single( x => (x.LocationID == CurrentLocation.LocationID && x.ProductID == p.ProductID)); LP.Inventory -= OP.Quantity; LocationProductsDAO.UpdateLocationProducts(LP, DB); } }
private void updatePublicControls() { List <Address> listA = AddressDAO.getUserList(user.idUser); List <Product> listP = ProductDAO.getList(); List <Order> listO = OrderDAO.getUserList(user.idUser); comboBox1.DataSource = null; comboBox1.DisplayMember = "address"; comboBox1.ValueMember = "idaddress"; comboBox1.DataSource = listA; comboBox6.DataSource = null; comboBox6.DisplayMember = "name"; comboBox6.ValueMember = "idproduct"; comboBox6.DataSource = listP; comboBox7.DataSource = null; comboBox7.DisplayMember = "address"; comboBox7.ValueMember = "idaddress"; comboBox7.DataSource = listA; comboBox8.DataSource = null; comboBox8.DisplayMember = "idorder"; comboBox8.ValueMember = "idorder"; comboBox8.DataSource = listO; dataGridView5.DataSource = null; dataGridView5.DataSource = listA; dataGridView4.DataSource = null; dataGridView4.DataSource = listO; }
// GET: OrderClient public ActionResult Index(int id, int page = 1, int pageSize = 5) { var order = new OrderDAO(); var model = order.OrderByUser(id, page, pageSize); return(View(model)); }
// GET: Admin/Order public ActionResult Index(int page = 1, int pageSize = 10) { OrderDAO dao = new OrderDAO(); var model = dao.ListAllPaging(page = 1, pageSize = 10); return(View(model)); }
public ActionResult DaThanhToan() { OrderDAO dao = new OrderDAO(); var model = dao.LayDonHangDaThanhToan(); return(View(model)); }
internal static (List <Order>, List <List <OrderProducts> >, List <List <Product> >) GetOrdersInfoFromLocation(Location CurrentLocation) { List <Order> OrdersFromLocation = new List <Order>(); List <List <OrderProducts> > OPs = new List <List <OrderProducts> >(); List <List <Product> > PIOs = new List <List <Product> >(); using (var DB = new P0Context()) { OrderDAO.LoadOrdersList(DB); OrdersFromLocation = DB.OrdersList.Where(o => o.LocationID == CurrentLocation.LocationID).ToList(); OrderProductsDAO.LoadOrderProductsList(DB); foreach (Order order in OrdersFromLocation) { List <OrderProducts> OrderProducts = DB.OrderProductsList.Where(o => o.OrderID == order.OrderID).ToList(); OPs.Add(OrderProducts); } ProductDAO.LoadProductsList(DB); foreach (List <OrderProducts> ops in OPs) { List <Product> ProductsInOrder = new List <Product>(); foreach (OrderProducts op in ops) { Product p = DB.ProductsList.First(p => p.ProductID == op.ProductID); ProductsInOrder.Add(p); } PIOs.Add(ProductsInOrder); } } return(OrdersFromLocation, OPs, PIOs); }
internal static void PlaceOrder(List <Product> ShoppingCart, Billing BillingInfo, Customer CurrentCustomer, Location CurrentLocation, List <int> Quantities) { DateTime now = System.DateTime.Now; using (var DB = new P0Context()) { Order Order = new Order { CustomerID = CurrentCustomer.CustomerID, LocationID = CurrentLocation.LocationID, OrderTime = now.ToString() }; OrderDAO.AddOrders(Order, DB); LocationProductsDAO.LoadLocationProductsList(DB); foreach (Product p in ShoppingCart) { int QuantityIndex = ShoppingCart.IndexOf(p); OrderProducts OP = new OrderProducts { OrderID = Order.OrderID, ProductID = p.ProductID, Quantity = Quantities[QuantityIndex] }; OrderProductsDAO.AddOrderProducts(OP, DB); LocationProducts LP = DB.LocationProductsList.Single( x => (x.LocationID == CurrentLocation.LocationID && x.ProductID == p.ProductID)); LP.Inventory -= OP.Quantity; LocationProductsDAO.UpdateLocationProducts(LP, DB); } } }
public void UpdateOrderTest() { Order order = new Order(); order.Date = DateTime.Now; order.IsPayed = true; order.Kinotheatr = "Red Star"; order.MovieId = 10; order.ClientId = 80; OrderDAO orderDAO = new OrderDAO(); orderDAO.AddOrder(order); List <Order> list = orderDAO.GetOrdersByMovie((int)order.MovieId); order = list[list.Count - 1]; order.MovieId = 90; orderDAO.UpdateOrder(order); list = orderDAO.GetOrdersByMovie((int)order.MovieId); string expected = ToStringWithoutId(order); string actual = ToStringWithoutId(list[list.Count - 1]); Assert.AreEqual(expected, actual); }
// GET: Admin/DonHang public ActionResult Index(string searchString, int page = 1, int pagesize = 10) { var dao = new OrderDAO(); var list = dao.ListAll(searchString, page, pagesize); return(View(list)); }
public ActionResult PaymentWithLogin() { if (ModelState.IsValid) { var user = new UserDAO().GetByUsername((string)Session[Constant.CUSTOMER_SESSION]); var orderInfo = new Order(); orderInfo.shipAddress = user.Address; orderInfo.shipEmail = user.Email; orderInfo.shipPhone = user.Phone; orderInfo.shipName = user.Name; var res = new OrderDAO().Create(orderInfo); if (res == -1) { return(RedirectToAction("Message", new { msg = "error" })); } else { setOrdelDetail(res); return(RedirectToAction("Message", new { msg = "success" })); } } else { return(RedirectToAction("Message", new { msg = "error" })); } }
public ActionResult Checkout(string receiver, string phone, string address) { User user = (User)Session["USER"]; if (user != null) { CartObj cart = (CartObj)Session["CART"]; if (cart != null) { DateTime date = DateTime.Now; OrderDAO daoOrder = new OrderDAO(); OrderDetailsDAO daoDetails = new OrderDetailsDAO(); Order order = new Order() { phone = phone, receiver = receiver, addressShip = address, username = user.username, orderDate= date}; daoOrder.Add(order); int currentID = daoOrder.GetCurrentOrderID(); foreach(var item in cart.cart) { OrderDetail details = new OrderDetail() { orderID = currentID, phoneID = item.Key.phoneID, price = item.Key.price, quantity = item.Value, discount = item.Key.discount }; daoDetails.Add(details); PhoneDAO daoPhone = new PhoneDAO(); daoPhone.UpdateQuantity(item.Value,item.Key.phoneID); } Session["CART"] = null; } } return RedirectToAction("Index", "Home", new { area = "" }); }
public InsertOrderCommand(OrderDAO order, int BeverId, int IdBill, int Amount) { this.order = order; this.BeverId = BeverId; this.IdBill = IdBill; this.Amount = Amount; }
protected void Button1_Click(object sender, EventArgs e) { if (Session["USERNAME"] == null && Session["UID"] == null) { Response.Redirect("~/Signin.aspx"); } BookDAO booktDao = new BookDAO(); OrderDAO oDao = new OrderDAO(); string bookid = Request.QueryString["book_id"]; int bid = Convert.ToInt32(bookid); string address = TextBox1.Text.Trim(); string uid = Session["UID"].ToString(); string no = DateTime.Now.Date.ToString(); if (address == "") { Label11.Text = "请输入您的收货地址"; } else { OrderDTO order = new OrderDTO(no, uid, address, bid); oDao.insertOrder(order); Label11.Text = "成功创建订单"; Button1.Enabled = false; Button1.Text = "已下单"; } }
public ActionResult Payment() { var order = new Model.EF.ORDER(); order.DATEBEGIN = DateTime.Now; try { var id = new OrderDAO().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDAO = new Model.DAO.OrderDetailDAO(); decimal total = 0; foreach (var item in cart) { var orderDetail = new Model.EF.ORDER_DETAIL(); orderDetail.ID_PRO = item.Product.ID_PRO; orderDetail.ID_CART = id; orderDetail.PRICE = item.Product.PRICE; orderDetail.SOLD_NUM = item.Quantity; detailDAO.Insert(orderDetail); total += (item.Product.PRICE.GetValueOrDefault(0) * item.Quantity); } } catch (Exception ex) { //ghi log throw ex; //return Redirect("/loi-thanh-toan"); } return(Redirect("/hoan-thanh")); }
// GET: Admin/OrderDetailAdmin public ActionResult Index(int id) { var orderDetail = new OrdersDetailDAO().Detail(id); List <OrdersDetailAdminModel> listO = new List <OrdersDetailAdminModel>(); foreach (var item in orderDetail) { var detail = new OrdersDetailAdminModel(); detail.BillID = item.id_Bill; detail.ID = item.id; detail.ProductID = item.Product.id; detail.ProductName = item.Product == null ? string.Empty : item.Product.name; detail.Price = item.price; detail.Qty = item.qty; detail.ProductImage = item.Product.imagemain; listO.Add(detail); } ViewBag.Product = listO; var order = new OrderDAO().Detail(id); ViewBag.Order = order; return(View()); }
public PartialViewResult DonHangDaGiao() { OrderDAO orderDAO = new OrderDAO(); ViewBag.DonHangDaGiao = orderDAO.DonHangDaGiao(); return(PartialView()); }
public PartialViewResult SoLuongDonHang() { OrderDAO orderDAO = new OrderDAO(); ViewBag.SoLuongDonHang = orderDAO.SoLuongDonHang(); return(PartialView()); }
public PartialViewResult TongTien() { OrderDAO orderDAO = new OrderDAO(); ViewBag.TongTien = orderDAO.TongTien(); return(PartialView()); }
public JsonResult Order_Statistics_ByDay(string fromDate, string toDate) { var fDate = DateTime.ParseExact(fromDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); var tDate = DateTime.ParseExact(toDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); var res = new OrderDAO().GetAll().GroupBy(_ => _.CreatedDate.Date).Select(_ => new OrderCountViewModel { date = _.Key, count = _.Count() }).ToList(); var allDate = new List <ChartsDataViewModel>(); var totalDays = (tDate - fDate).TotalDays; for (DateTime i = fDate; i <= tDate; i = i.AddDays(1)) { var item = new ChartsDataViewModel(); item.value = "0"; foreach (var jtem in res) { if (jtem.date.Date == i.Date.Date) { item.value = jtem.count.ToString(); } } item.date = i; allDate.Add(item); } return(Json(new { label = "Thống kê đơn hàng", data = allDate }, JsonRequestBehavior.AllowGet)); }
//Constructor: public OrderController() { string connection = ConfigurationManager.ConnectionStrings["soundEquipmentDatabase"].ConnectionString; _orderDataAccess = new OrderDAO(connection); _productDataAccess = new ProductDAO(connection); }
public ActionResult Payment(string shipId, string amount, string shipNote) { var order = new Order(); order.date_created = DateTime.Now; order.id_User = Convert.ToInt32(shipId); order.note = shipNote; order.status = 0; order.amount = Convert.ToDouble(amount); try { var id = new OrderDAO().Insert(order); var cart = (List <CartItemModel>)Session[CartSession]; var detail = new OrdersDetailDAO(); foreach (var item in cart) { var ordersDetail = new OrdersDetail(); ordersDetail.id_Product = item.Product.id; ordersDetail.id_Bill = (int)id; ordersDetail.price = item.Product.price; ordersDetail.qty = item.Qty; ordersDetail.date_created = DateTime.Now; detail.Insert(ordersDetail); } } catch { return(RedirectToAction("Error", "CartClient")); } return(RedirectToAction("Sussecc", "CartClient")); }
protected void btnExcel_Click(object sender, EventArgs e) { ListView lvExcel = (ListView)Page.LoadControl("~/Controls/ExcelTemplate/RemainOrderDetailReport.ascx").Controls[0]; lvExcel.Attributes["txtDealerCode"] = txtDealerCode.Text.Trim(); lvExcel.Attributes["txtIssueFrom"] = txtIssueFrom.Text.Trim(); lvExcel.Attributes["txtIssueNo"] = txtIssueNo.Text.Trim(); lvExcel.Attributes["txtIssueTo"] = txtIssueTo.Text.Trim(); lvExcel.Attributes["txtOrderFrom"] = txtOrderFrom.Text.Trim(); lvExcel.Attributes["txtOrderNo"] = txtOrderNo.Text.Trim(); lvExcel.Attributes["txtOrderTo"] = txtOrderTo.Text.Trim(); lvExcel.Attributes["ddlArea"] = ddlArea.SelectedValue; var odao = new OrderDAO(); //lvExcel.DataSource = odao.FindByCodes(-1, -1, txtDealerCode.Text.Trim(), ddlArea.SelectedValue, ""); lvExcel.DataSource = odao.GetDealerHasOrderRemain(-1, -1, ddlArea.SelectedValue, txtOrderNo.Text.Trim(), txtOrderFrom.Text.Trim(), txtOrderTo.Text.Trim(), txtIssueNo.Text.Trim(), txtIssueFrom.Text.Trim(), txtIssueTo.Text.Trim(), txtDealerCode.Text.Trim()); if (odao.CountDealerHasOrderRemain(null, null, null, null, null, null, null, null) > 0) { lvExcel.DataBind(); GridView2Excel.Export(lvExcel, "RemainOrderDetailReport.xls"); } }
public OrderBUS() { oDao = new OrderDAO(); }
static OrderController() { dao = new OrderDAO(); }
public MapModel GetMapModel() { User user = CurrentUser.Current; Kingdom userKingdom = new KingdomDAO().GetByUserId(user.UserId); IList<Kingdom> kingdoms = new KingdomDAO().GetByMapId(userKingdom.MapId); List<Owner> players = new List<Owner>(); Random random = new Random(); foreach (Kingdom k in kingdoms) { if (k.KingdomId == userKingdom.KingdomId) { players.Add(new Owner(userKingdom.KingdomId, userKingdom.KingdomName, "#FF0000")); } else { players.Add(new Owner(k.KingdomId, k.KingdomName, String.Format("#{0:X6}", random.Next(0x1000000)))); } } List<TileInfo> tiles = new List<TileInfo>(); IList<Field> fields = new FieldDAO().GetByMapId(userKingdom.MapId); foreach (Field field in fields) { IList<Unit> units = new UnitDAO().GetFromArea(field.MapId, field.FieldX, field.FieldY, 1, 1); int unitCount = 0; foreach (Unit u in units) { unitCount += u.Count; } tiles.Add(new TileInfo(field.FieldId, field.FieldX, field.FieldY, field.FieldName, field.KingdomId, unitCount)); } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Orders need to be taken away from the database too !!!!!!!!!!!!!!!!!!1 List<OrderInfo> orders = new List<OrderInfo>(); IList<Order> ordersDB = new OrderDAO().GetByKingdomEpoch(userKingdom.KingdomId, new EpochDAO().GetCurrentByMapId(userKingdom.MapId).EpochId); Dictionary<int,UnitType> unitTypes = new Dictionary<int,UnitType>(); IList<UnitType> unitTypesAll = new UnitTypeDAO().GetAll(); foreach (UnitType ut in unitTypesAll) { unitTypes.Add(ut.UnitTypeId,ut); } foreach (Order o in ordersDB) { if (o.OrderTypeName.Equals("Buy")) { orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, unitTypes[o.UnitTypeId].UnitTypeCost * o.Count)); } else { orders.Add(new OrderInfo(o.OrderTypeName, o.FieldId, o.FieldIdDestination, o.Count, 0)); } } //orders.Add(new OrderInfo("Defend",1,1,5,0)); //int rice = 1000; //List<Owner> players = new List<Owner>(); //Owner owner1 = new Owner(1, "Moose", "#ff0000"); //Owner owner2 = new Owner(2, "Lucas", "#00ff00"); //players.Add(owner1); //players.Add(owner2); //List<TileInfo> tiles = new List<TileInfo>(); //tiles.Add(new TileInfo(1,1,1,"Krwawe wzgórza", owner1.playerId, 5)); //tiles.Add(new TileInfo(2,2,1,"MooseVille", owner1.playerId, 5)); //tiles.Add(new TileInfo(3,2,2,"Grunwald", owner1.playerId, 5)); //tiles.Add(new TileInfo(4,1,2,"Bździochy dolne", null, 5)); //tiles.Add(new TileInfo(5,3,4,"Cukierkowa Dolina", owner2.playerId, 10)); //tiles.Add(new TileInfo(6,5,5,"Wilczy Szaniec", owner2.playerId, 10)); //List<OrderInfo> orders = new List<OrderInfo>(); //orders.Add(new OrderInfo("Defend",1,1,5,0)); return new MapModel(userKingdom.KingdomResources, tiles, players, orders); }
public String Update(int MapId) { IList<Field> fields = new FieldDAO().GetByMapId(MapId); Epoch epoch = new EpochDAO().GetCurrentByMapId(MapId); // wypuszczenie wojsk z pól IList<Order> orders = new OrderDAO().GetByEpoch(epoch.EpochId); foreach (Order o in orders) { if (o.OrderTypeName.Equals("Move") || o.OrderTypeName.Equals("Defend")) { Field f = new FieldDAO().GetById(o.FieldId); Dictionary<int, int> unitModifier = new Dictionary<int, int>(); unitModifier[o.UnitTypeId] = -o.Count; UnitUpdate(f.KingdomId, f, unitModifier); } } Dictionary<int,UnitType> unitTypes = new Dictionary<int,UnitType>(); foreach(UnitType ut in new UnitTypeDAO().GetAll()) { unitTypes.Add(ut.UnitTypeId,ut); } // rozpatrywanie rozkazów foreach (Field field in fields) { IList<Order> ordersAll = new OrderDAO().GetByFieldEpoch(epoch.EpochId, field.FieldId); if (ordersAll.Count > 0) { IList<Order> orderMove = new List<Order>(); IList<Order> orderDefend = new List<Order>(); IList<Order> orderBuy = new List<Order>(); IList<Order> orderGather = new List<Order>(); // Podział rozkazów według rodzaju foreach (Order order in ordersAll) { if (order.OrderTypeName.Equals("Move")) { orderMove.Add(order); } else if (order.OrderTypeName.Equals("Defend")) { orderDefend.Add(order); } else if (order.OrderTypeName.Equals("Buy")) { orderBuy.Add(order); } else if (order.OrderTypeName.Equals("Gather")) { orderGather.Add(order); } } // królestwo do którego naley pole na początku tury Kingdom startKingdom = new KingdomDAO().GetInfoById(field.KingdomId); if (startKingdom.KingdomId!=0) { // zbieranie ryżu int collectedRice = 0; foreach (Order o in orderGather) { collectedRice += o.Count * RICE_BY_ONE_MAN; } startKingdom.KingdomResources += collectedRice; // rekrutacja Dictionary<int, int> unitModifier = new Dictionary<int, int>(); int toPay = 0; foreach (Order o in orderBuy) { if (unitModifier.ContainsKey(o.UnitTypeId)) { unitModifier[o.UnitTypeId] += o.Count; } else { unitModifier[o.UnitTypeId] = o.Count; } toPay += o.Count * unitTypes[o.UnitTypeId].UnitTypeCost; } UnitUpdate(startKingdom.KingdomId, field, unitModifier); startKingdom.KingdomResources -= toPay; new KingdomDAO().Update(startKingdom); } // af[kingdom][unitType] = count Dictionary<int, Dictionary<int, int>> attackForces = new Dictionary<int, Dictionary<int, int>>(); foreach (Order o in orderDefend.Concat(orderMove)) { if (!attackForces.ContainsKey(o.KingdomId)) { attackForces[o.KingdomId] = new Dictionary<int, int>(); } if (attackForces[o.KingdomId].ContainsKey(o.UnitTypeId)) { attackForces[o.KingdomId][o.UnitTypeId] += o.Count; } else { attackForces[o.KingdomId][o.UnitTypeId] = o.Count; } } int winner = Battle(attackForces); if (winner == 0) { // nic sie nie dzieje // wszyscy bioracy udzial w walkach zostali wycieci w pień, więc nie ma kto wrócić na pole } else if (winner == startKingdom.KingdomId) { UnitUpdate(startKingdom.KingdomId, field, attackForces[startKingdom.KingdomId]); } else { field.KingdomId = winner; new FieldDAO().Update(field); UnitUpdate(winner, field, attackForces[winner]); } } } new EpochDAO().Add(MapId); this.DiplomacyStatusUpdate(MapId,fields); return "Hello world"; // 1: wyciągnąc z bazy wszystkie pola danej mapy // 2: Dla każdego pola wyciągnąc jego rozkazy // 3: Rozdzielić rozkazy według typu // 4: Rozpatrzyć zbieranie ryżu // 5: Rozpatrzyc rekrutacje // 6: Rozpatrzec ataki i obrone }
public void removeOrder(OrderInfo orderInfo) { Order o = new OrderDAO().GetByFieldEpochOrderTypeName(new EpochDAO().GetCurrentByMapId(new KingdomDAO().GetByUserId(CurrentUser.KingdomId).MapId).EpochId, orderInfo.sourceTileId, orderInfo.destinationTileId, orderInfo.orderType); new OrderDAO().DeleteById(o.OrderId); }