Esempio n. 1
0
        public IActionResult MyOrders()
        {
            //Get the orders bound to the current userId
            //The email
            string userEmail = this.HttpContext.Session.GetString("User");

            //tbl_orders
            Dictionary <string, object> dic = new Dictionary <string, Object>();

            dic.Add("in_givenEmail", userEmail);
            List <Order> orders = ProcedureCall <Order> .returnResultList(dic, "util_GetOrders");

            //Instantiate lists
            List <List <tbl_orderhistory> > orderHistories = new List <List <tbl_orderhistory> >();

            List <tbl_orderstatus> orderStatuses = new List <tbl_orderstatus>();

            List <OfferedLabourerService> olsList = new List <OfferedLabourerService>();


            //Get all the relevant data
            for (int i = 0; i < orders.Count; i++)
            {
                Dictionary <string, Object> dic2 = new Dictionary <string, Object>();
                dic2.Add("in_orderid", orders[i].fld_OrderId);
                //tbl orderhistory
                List <tbl_orderhistory> orderhistories = ProcedureCall <tbl_orderhistory> .returnResultList(dic2, "util_GetOrderHistories").OrderByDescending(s => s.fld_ActionDate).ToList();

                //tbl_orderstatus
                tbl_orderstatus orderstatus = ProcedureCall <tbl_orderstatus> .ExecuteReader(dic2, "util_GetOrderStatuses");

                //tbl_offeredlabourerservice
                OfferedLabourerService ols = EsOLSQuery <OfferedLabourerService> .findByOfferedServiceId(orders[i].fld_OfferedServiceId);

                //Add it all to their respectiv lists
                orderStatuses.Add(orderstatus);
                olsList.Add(ols);
                orderHistories.Add(orderhistories);
            }


            Tuple <List <Order>, List <tbl_orderstatus>, List <List <tbl_orderhistory> >, List <OfferedLabourerService> > tuple = Tuple.Create(orders, orderStatuses, orderHistories, olsList);

            return(View(tuple));
        }
        public async Task <IActionResult> Success()
        {
            //This action returns the result of the payment.
            //This is when the order will receive it's first update: it's either payed or encountered an error.
            var result = PDTHolder.Success(Request.Query["tx"].ToString());

            //Update the order status and history, update the offeredservice


            //Get previously entered order information
            string form      = HttpContext.Session.GetString("FORM");
            char   separator = ';';

            string[] formVars = form.Split(separator);

            //Send a confirmation email
            await ConstructOrderVerificationMailAsync(formVars);


            string     email             = formVars[4];
            List <int> offeredServiceIds = ParsePursToList();

            foreach (int olsId in offeredServiceIds)
            {
                //Fetch the order id
                int orderId = MollShopContext.FindOrderId(olsId, email);


                //Insert a new order history
                tbl_orderhistory history = new tbl_orderhistory();
                history.fld_ActionDate  = DateTime.Now;
                history.fld_lastAction  = "Paid order";
                history.fld_orderstatus = "Sent";
                history.fld_orderid     = orderId;

                MollShopContext.CreateRow(history, "tbl_orderhistory");

                //Insert a new order status
                tbl_orderstatus orderStatus = new tbl_orderstatus();
                orderStatus.fld_dateOrdered        = DateTime.Now;
                orderStatus.fld_orderid            = orderId;
                orderStatus.fld_targetDeliveryDate = DateTime.Now.AddDays(7);
                orderStatus.fld_DateUpdated        = DateTime.Now;
                MollShopContext.CreateRow(orderStatus);

                //Set the availability of the service to 'N'

                //ElasticSearch
                EsUpdater <OfferedLabourerService> .UpdateField("" + olsId, "fld_stillavailable", 'N');

                //Database
                tbl_offeredservicesdata os = new tbl_offeredservicesdata();
                os.fld_stillavailable = 'N';

                MollShopContext.UpdateRow(os, "fld_OfferedServiceId", olsId);
            }



            return(View("Success"));
        }