public void Create(order_items product) { if (!UpdateDatabase) { var first = GetAll().OrderByDescending(e => e.id).FirstOrDefault(); var id = (first != null) ? first.id : 0; product.id = id + 1; entities.order_items.Add(product); entities.SaveChanges(); } else { var entity = new order_items(); entity.item_id = product.item_id; entity.oid = product.oid; entity.qty = product.qty; entity.total = product.total; entity.profit = product.profit; entity.disc = product.disc; entities.order_items.Add(entity); entities.SaveChanges(); product.id = entity.id; } }
// GET: OrderItemsMain/Details/5 public ActionResult Details(int id) { order_items order_itemss = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54964/api/Order_ItemsApi"); //HTTP GET var responseTask = client.GetAsync("Order_ItemsApi?id=" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <order_items>(); readTask.Wait(); order_itemss = readTask.Result; } else //web api sent error response { //log response status here.. ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } } return(View(order_itemss)); }
public IHttpActionResult Putorder_items(int id, order_items order_items) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order_items.Id) { return(BadRequest()); } db.Entry(order_items).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!order_itemsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(order_items product) { if (!UpdateDatabase) { var target = One(e => e.id == product.id); if (target != null) { target.item_id = product.item_id; target.qty = product.qty; target.total = product.total; target.profit = product.profit; target.disc = product.disc; } entities.SaveChanges(); } else { var entity = new order_items(); entity.item_id = product.item_id; entity.qty = product.qty; entity.total = product.total; entity.profit = product.profit; entity.disc = product.disc; entities.order_items.Attach(entity); entities.Entry(entity).State = EntityState.Modified; entities.SaveChanges(); } }
public IHttpActionResult Postorder_items(order_items order_items) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.order_items.Add(order_items); try { db.SaveChanges(); } catch (DbUpdateException) { if (order_itemsExists(order_items.order_id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = order_items.order_id }, order_items)); }
public ActionResult DeleteConfirmed(int id) { order_items order_items = db.order_items.Find(id); db.order_items.Remove(order_items); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult Getorder_items(int id) { order_items order_items = db.order_items.Find(id); if (order_items == null) { return(NotFound()); } return(Ok(order_items)); }
public ActionResult Edit([Bind(Include = "order_id,item_id,product_id,quantity,list_price,discount")] order_items order_items) { if (ModelState.IsValid) { db.Entry(order_items).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.product_id = new SelectList(db.products, "product_id", "product_name", order_items.product_id); ViewBag.order_id = new SelectList(db.orders, "order_id", "order_id", order_items.order_id); return(View(order_items)); }
public IHttpActionResult Postorder_items(order_items order_items) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.order_items.Add(order_items); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = order_items.Id }, order_items)); }
// GET: OrderItems/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } order_items order_items = db.order_items.Find(id); if (order_items == null) { return(HttpNotFound()); } return(View(order_items)); }
public IHttpActionResult Deleteorder_items(int id) { order_items order_items = db.order_items.Find(id); if (order_items == null) { return(NotFound()); } db.order_items.Remove(order_items); db.SaveChanges(); return(Ok(order_items)); }
// GET: OrderItems/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } order_items order_items = db.order_items.Find(id); if (order_items == null) { return(HttpNotFound()); } ViewBag.product_id = new SelectList(db.products, "product_id", "product_name", order_items.product_id); ViewBag.order_id = new SelectList(db.orders, "order_id", "order_id", order_items.order_id); return(View(order_items)); }
private void saveOrderItems(int oid) { order_itemsModel oic = new order_itemsModel(); for (int i = 0; i < ids.Length; i++) { order_items oi = new order_items(); oi.oid = oid; oi.item_id = ids[i]; oi.qty = qnty[i]; oi.total = total[i]; oi.disc = 0; oi.profit = getItemProfit(i); oic.Create(oi); } }
public ActionResult Delete(int id, order_items order_itemss) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54964/api/Order_ItemsApi"); //HTTP DELETE var deleteTask = client.DeleteAsync("Order_ItemsApi/" + id.ToString()); deleteTask.Wait(); var result = deleteTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
public ActionResult Edit(int id, order_items order_itemss) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54964/api/Order_ItemsApi"); //HTTP POST var putTask = client.PutAsJsonAsync <order_items>("Order_ItemsApi?id=" + id.ToString(), order_itemss); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(order_itemss)); }
public ActionResult Create(order_items order_itemss) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54964/api/Order_ItemsApi"); var postTask = client.PostAsJsonAsync <order_items>("Order_ItemsApi", order_itemss); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } } return(View("Create")); }
public static List <order_items> GetOrderItems() { String query = "SELECT * FROM order_items"; List <order_items> list_ord_items = new List <order_items>(); using (SqlCommand com = new SqlCommand(query, db.GetConnection())) { SqlDataReader reader = com.ExecuteReader(); while (reader.Read()) { order_items ord_item = new order_items(); ord_item.order_item_id = (Int32)reader["order_item_id"]; ord_item.quantity_in_order = (Int32)reader["quantity_in_order"]; ord_item.id_order = (Int32)reader["id_order"]; ord_item.id_product = (Int32)reader["id_product"]; list_ord_items.Add(ord_item); } db.CloseConnection(); } return(list_ord_items); }
// ORDER ITEMS private void Button_add_items_Click(object sender, EventArgs e) { bool flag = true; try { var order_item = new order_items { product_id = Convert.ToInt32(dropDownList_product.SelectedValue), order_id = Convert.ToInt32(dropDownList_order.SelectedValue), order_quantity = Convert.ToInt32(text_order_quantity.Text.ToString()) }; product product = db.products.Where(p => p.id == order_item.product_id).First(); if (order_item.order_quantity > product.quantityInStock) { flag = false; MessageBox.Show("There Is not enough products to add them to order ! There Is just " + product.quantityInStock + " left :<"); } if (IsInputValid(order_item) && flag && ShowConfirmMessage("add", "item")) { db.order_items.Add(order_item); product.quantityInStock = product.quantityInStock - order_item.order_quantity; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); this.order_itemsTableAdapter.Fill(this.dataSet.order_items); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public ActionResult Index(customer customer) { if (Session["user"] == null) { TempData["error2"] = "Bạn cần đăng nhập trước khi Order !."; return(RedirectToAction("Login", "Account")); } if (Session["Cart"] == null) { ViewBag.error = "Giỏ hàng của bạn đang trống !"; return(Index()); } if (ModelState.IsValid) { order order = new order { customer_id = ((Session["user"] as customer).customer_id), first_name = customer.first_name, last_name = customer.last_name, email = customer.email, //staff_id = 6, phone = customer.phone, street = customer.street, city = customer.city, zip_code = customer.zip_code, order_status = false, order_date = DateTime.Now, shipped_date = DateTime.Now.AddDays(4) }; db.orders.Add(order); db.SaveChanges(); List <CartItem> cart = (List <CartItem>)Session["Cart"]; Xmail.XMail.Send(order.email, 1, 0, order, cart); List <staff> staff = db.staffs.ToList(); foreach (var item in staff) { Xmail.XMail.Send(item.email, 0, 0, order, cart); } ViewBag.success = "Đặt hàng thành công!"; for (int i = 0; i < cart.Count; i++) { order_items item = new order_items { order_id = order.order_id, product_id = cart[i].cart.product_id, quantity = cart[i].quantity, list_price = cart[i].cart.list_price }; product product = db.products.Find(cart[i].cart.product_id); product.quantity = product.quantity - cart[i].quantity; db.order_items.Add(item); db.SaveChanges(); } Session.Remove("Cart"); return(Index()); } else { return(Index()); } }
/// <summary> /// GetdataFromMySQL /// </summary> /// <param name="ConString"></param> public static void GetdataFromMySQL(string ConString) { string apiResponse = string.Empty; string apiGenPickupRes = string.Empty; string apiGenMenifestRes = string.Empty; AWBResponce awbResponce = new AWBResponce(); PickupResponce pickupResponce = new PickupResponce(); ManifestResponce manifestResponce = new ManifestResponce(); MySqlConnection con = null; try { DataSet ds = new DataSet(); AWBRequest objdetails = new AWBRequest(); orderDetails orderDetails = new orderDetails(); IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json", true, true).Build(); string ClientAPIURL = config.GetSection("MySettings").GetSection("ClientAPIURL").Value; con = new MySqlConnection(ConString); MySqlCommand cmd = new MySqlCommand("SP_PHYGetOrderdetailForAWB", con) { CommandType = System.Data.CommandType.StoredProcedure }; cmd.Connection.Open(); MySqlDataAdapter da = new MySqlDataAdapter(cmd); da.Fill(ds); cmd.Connection.Close(); if (ds != null && ds.Tables[0] != null) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { try { if (ds != null && ds.Tables[1] != null) { objdetails = new AWBRequest() { pickup_postcode = ds.Tables[1].Rows[i]["pickup_postcode"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[1].Rows[i]["pickup_postcode"]), delivery_postcode = ds.Tables[1].Rows[i]["delivery_postcode"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[1].Rows[i]["delivery_postcode"]), weight = ds.Tables[1].Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[1].Rows[i]["Weight"]), orderDetails = new orderDetails() }; } orderDetails = new orderDetails { Id = ds.Tables[0].Rows[i]["ID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["ID"]), order_id = ds.Tables[0].Rows[i]["InvoiceNo"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["InvoiceNo"]), order_date = ds.Tables[0].Rows[i]["Date"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["Date"]), billing_customer_name = ds.Tables[0].Rows[i]["CustomerName"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["CustomerName"]), billing_address = ds.Tables[0].Rows[i]["ShippingAddress"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["ShippingAddress"]), billing_city = ds.Tables[0].Rows[i]["City"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["City"]), billing_pincode = ds.Tables[0].Rows[i]["delivery_postcode"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["delivery_postcode"]), billing_state = ds.Tables[0].Rows[i]["State"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["State"]), billing_country = ds.Tables[0].Rows[i]["Country"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["Country"]), //billing_email = ds.Tables[0].Rows[i]["EmailID"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["EmailID"]), billing_phone = ds.Tables[0].Rows[i]["MobileNumber"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["MobileNumber"]), shipping_customer_name = ds.Tables[0].Rows[i]["CustomerName"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["CustomerName"]), shipping_address = ds.Tables[0].Rows[i]["ShippingAddress"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["ShippingAddress"]), shipping_city = ds.Tables[0].Rows[i]["City"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["City"]), shipping_pincode = ds.Tables[0].Rows[i]["delivery_postcode"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["delivery_postcode"]), shipping_country = ds.Tables[0].Rows[i]["Country"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["Country"]), shipping_state = ds.Tables[0].Rows[i]["State"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["State"]), //shipping_email = ds.Tables[0].Rows[i]["EmailID"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["EmailID"]), shipping_phone = ds.Tables[0].Rows[i]["MobileNumber"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["MobileNumber"]), shipping_is_billing = true, billing_email = "*****@*****.**", shipping_email = "*****@*****.**", payment_method = "Prepaid", pickup_location = "Test", channel_id = "633828", billing_last_name = "", billing_address_2 = "", billing_alternate_phone = "", shipping_last_name = "", shipping_address_2 = "", sub_total = ds.Tables[0].Rows[i]["Amount"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["Amount"]), length = ds.Tables[0].Rows[i]["Length"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["Length"]), breadth = ds.Tables[0].Rows[i]["Breath"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["Breath"]), height = ds.Tables[0].Rows[i]["Height"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["Height"]), weight = ds.Tables[0].Rows[i]["Weight"] == DBNull.Value ? 0 : Convert.ToDecimal(ds.Tables[0].Rows[i]["Weight"]), StoreDelivery = Convert.ToBoolean(ds.Tables[0].Rows[i]["StoreDelivery"]), TenantId = ds.Tables[0].Rows[i]["TenantId"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["TenantId"]), StoreId = ds.Tables[0].Rows[i]["StoreId"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[0].Rows[i]["StoreId"]), ProgramCode = ds.Tables[0].Rows[i]["ProgramCode"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[i]["ProgramCode"]), order_items = new List <order_items>() }; List <order_items> listobj = new List <order_items>(); string ItemIDs = ""; for (int j = 0; j < ds.Tables[2].Rows.Count; j++) { if (Convert.ToInt32(ds.Tables[2].Rows[j]["OrderID"]) == Convert.ToInt32(orderDetails.Id)) { order_items objorder_Items = new order_items() { OrderItemID = ds.Tables[2].Rows[j]["ID"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[2].Rows[j]["ID"]), name = ds.Tables[2].Rows[j]["ItemName"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[2].Rows[j]["ItemName"]), sku = ds.Tables[2].Rows[j]["ItemID"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[2].Rows[j]["ItemID"]), units = ds.Tables[2].Rows[j]["Quantity"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[2].Rows[j]["Quantity"]), selling_price = ds.Tables[2].Rows[j]["ItemPrice"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[2].Rows[j]["ItemPrice"]) }; listobj.Add(objorder_Items); ItemIDs += ds.Tables[2].Rows[j]["ID"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[2].Rows[j]["ID"]) + ","; } } ItemIDs = ItemIDs.TrimEnd(','); /*Check the Pincode Deliver or not*/ HSChkCourierAvailibilty hSChkCourierAvailibilty = new HSChkCourierAvailibilty { Pickup_postcode = objdetails.pickup_postcode, Delivery_postcode = objdetails.delivery_postcode }; ResponseCourierAvailibilty responseCourierAvailibilty = new ResponseCourierAvailibilty(); responseCourierAvailibilty = CheckClientPinCodeForCourierAvailibilty(hSChkCourierAvailibilty, orderDetails.TenantId, orderDetails.Id, ClientAPIURL); /*Check the Pincode Deliver or not*/ if (responseCourierAvailibilty.Available == "false") { if (orderDetails.StoreDelivery == true) { AddStoreResponse(orderDetails.Id, ItemIDs, orderDetails.TenantId, true, ConString); } else { AddStoreResponse(orderDetails.Id, ItemIDs, orderDetails.TenantId, false, ConString); } } else if (responseCourierAvailibilty.Available == "true") { orderDetails.order_items = listobj; ItemIDs = ItemIDs.TrimEnd(','); objdetails.orderDetails = orderDetails; string apiReq = JsonConvert.SerializeObject(objdetails); apiResponse = CommonService.SendApiRequest(ClientAPIURL + "/api/ShoppingBag/GetCouriersPartnerAndAWBCode", apiReq); awbResponce = JsonConvert.DeserializeObject <AWBResponce>(apiResponse); if (awbResponce.data != null) { if (awbResponce.data.awb_code != "" && awbResponce.data.courier_name != "" && awbResponce.statusCode == "200") { InsertCourierResponse(orderDetails.Id, ItemIDs, awbResponce.data.awb_code, awbResponce.data.courier_company_id, awbResponce.data.courier_name, awbResponce.data.order_id, awbResponce.data.shipment_id, ConString); CommonService.SmsWhatsUpDataSend(orderDetails.TenantId, 0, orderDetails.ProgramCode, orderDetails.Id, ClientAPIURL, "AWBAssigned", ConString); if (awbResponce != null) { if (awbResponce.data != null) { if (awbResponce.data.shipment_id != null) { PickupManifestRequest pickupManifestRequest = new PickupManifestRequest() { shipmentId = new List <int> { Convert.ToInt32(awbResponce.data.shipment_id) } }; try { string apiGenPickupReq = JsonConvert.SerializeObject(pickupManifestRequest); apiGenPickupRes = CommonService.SendApiRequest(ClientAPIURL + "/api/ShoppingBag/GeneratePickup", apiGenPickupReq); pickupResponce = JsonConvert.DeserializeObject <PickupResponce>(apiGenPickupRes); //if (pickupResponce.response.pickupTokenNumber != "") //{ // UpdateGeneratePickupManifest(orderDetails.Id, orderDetails.TenantId, orderDetails.Id, "Pickup", ConString); //} if (pickupResponce.status_code == 0 && pickupResponce.pickupStatus == "1") { if (pickupResponce.response != null) { if (pickupResponce.response.pickupTokenNumber != null) { //UpdateGeneratePickupManifest(ID, "Pickup", ConString, TenantId); UpdateGeneratePickupManifest(orderDetails.Id, orderDetails.TenantId, orderDetails.Id, "Pickup", ConString); CommonService.SmsWhatsUpDataSend(orderDetails.TenantId, 0, orderDetails.ProgramCode, orderDetails.Id, ClientAPIURL, "PickupScheduled", ConString); } } } else { ExLogger(orderDetails.Id, orderDetails.order_id, Convert.ToString(DateTime.Now), Convert.ToString(orderDetails.StoreId), pickupResponce.status_code + " : " + pickupResponce.message, apiGenPickupRes, ConString); } } catch (Exception ex) { ExLogger(orderDetails.Id, orderDetails.order_id, orderDetails.order_date, Convert.ToString(orderDetails.StoreId), ex.Message, ex.StackTrace, ConString); } try { string apiGenMenifestReq = JsonConvert.SerializeObject(pickupManifestRequest); apiGenMenifestRes = CommonService.SendApiRequest(ClientAPIURL + "/api/ShoppingBag/GenerateManifest", apiGenMenifestReq); manifestResponce = JsonConvert.DeserializeObject <ManifestResponce>(apiGenMenifestRes); if (manifestResponce.status_code == 0) { if (manifestResponce.status == "1" && manifestResponce.manifestUrl != null && manifestResponce.manifestUrl != "") { UpdateGeneratePickupManifest(orderDetails.Id, orderDetails.TenantId, orderDetails.Id, "Manifest", ConString); CommonService.SmsWhatsUpDataSend(orderDetails.TenantId, 0, orderDetails.ProgramCode, orderDetails.Id, ClientAPIURL, "ManifestGenerated", ConString); } else { ExLogger(orderDetails.Id, orderDetails.order_id, Convert.ToString(DateTime.Now), Convert.ToString(orderDetails.StoreId), manifestResponce.status, apiGenMenifestRes, ConString); } } else { ExLogger(orderDetails.Id, orderDetails.order_id, Convert.ToString(DateTime.Now), Convert.ToString(orderDetails.StoreId), manifestResponce.status_code + " : " + manifestResponce.message, apiGenMenifestRes, ConString); } } catch (Exception ex) { ExLogger(orderDetails.Id, orderDetails.order_id, orderDetails.order_date, Convert.ToString(orderDetails.StoreId), ex.Message, ex.StackTrace, ConString); } } } } } else { AddStoreResponse(orderDetails.Id, ItemIDs, orderDetails.TenantId, false, ConString); } } else { AddStoreResponse(orderDetails.Id, ItemIDs, orderDetails.TenantId, false, ConString); } } } catch (Exception Ex) { ExLogger(orderDetails.Id, orderDetails.order_id, orderDetails.order_date, Convert.ToString(orderDetails.StoreId), Ex.Message, Ex.StackTrace, ConString); } } } } catch (Exception ex) { } finally { if (con != null) { con.Close(); } GC.Collect(); } }