public OfferedLabourerService UpdateOLS(string insertedDic)
        {
            tbl_offeredservicesdata currentOffer = JsonConvert.DeserializeObject <tbl_offeredservicesdata>(insertedDic);

            MollShopContext.UpdateRow(currentOffer, "fld_offeredserviceid", currentOffer.fld_offeredserviceid);

            //Because ElasticSearch does not support decimal numbers, we must multiply the cost by a 100
            currentOffer.fld_cost = currentOffer.fld_cost * 100;

            OfferedLabourerService currentOLS = EsOLSQuery <OfferedLabourerService> .findByOfferedServiceId(currentOffer.fld_offeredserviceid);

            currentOLS.fld_cost           = currentOffer.fld_cost;
            currentOLS.fld_area           = currentOffer.fld_area;
            currentOLS.fld_timefirst      = currentOffer.fld_timefirst;
            currentOLS.fld_timelast       = currentOffer.fld_timelast;
            currentOLS.fld_stillavailable = currentOffer.fld_stillavailable;



            EsUpdater <OfferedLabourerService> .UpsertDocument(currentOLS, "moll_ols", "OLS", currentOLS.fld_offeredserviceid);

            //To render it correctly in the datatable, we divice the cost by 100 again
            currentOLS.fld_cost = currentOLS.fld_cost / 100;

            return(currentOLS);
        }
        public IActionResult SearchResult(OLSSearchModel ols)
        {
            //Deze Action rendert het resultaat van een search
            //Eerst verkrijgt het variabelen afkomstig van de searchform. Die stuurt ie door naar de ESQuery classes
            //Vervolgens verkrijgt hij dan van die ESQuery classes een package. Die gebruikt hij om zichzelf weer te renderen
            //List<OfferedLabourerService> package = EsOLSQuery<string>.mostFavourited();

            System.Diagnostics.Debug.WriteLine("Start Search: " + DateTime.Now.AddDays(-20));
            List <OfferedLabourerService> newPackage = EsOLSQuery <OfferedLabourerService> .generalSearchQuery(ols, 20);

            System.Diagnostics.Debug.WriteLine("Search completed: " + DateTime.Now.AddDays(-20));

            return(PartialView(newPackage));
        }
        public static List <OfferedLabourerService> fetchItemsInCookies(List <string> keyList)
        {
            List <OfferedLabourerService> packageList = new List <OfferedLabourerService>();

            foreach (string key in keyList)
            {
                int offeredServiceId = Convert.ToInt32(key.Substring(2));

                OfferedLabourerService ols = EsOLSQuery <string> .findByOfferedServiceId(offeredServiceId);

                packageList.Add(ols);
            }
            return(packageList);
        }
        public List <OfferedLabourerService> ParsePursToOls()
        {
            string pur       = this.HttpContext.Session.GetString("PUR");
            string purs      = pur.Substring(1);
            char   separator = ' ';

            string[] orderIds = purs.Split(separator);

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

            foreach (string id in orderIds)
            {
                int olsId = Convert.ToInt32(id);
                olsList.Add(EsOLSQuery <OfferedLabourerService> .findByOfferedServiceId(olsId));
            }
            return(olsList);
        }
示例#5
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));
        }
        //This action checks for dependencies. For instance, if a service is currently in an OfferedLabourerService.
        public int checkForDependency(int id, string type)
        {
            switch (type)
            {
            case "tbl_servicedata":
                List <OfferedLabourerService> packages = EsOLSQuery <tbl_servicedata> .getByService(id);

                return(packages.Count);

            case "tbl_labourerdata":
                List <OfferedLabourerService> Olspackages = EsOLSQuery <tbl_servicedata> .getByLabourer(id);

                return(Olspackages.Count);

            default:
                return(0);
            }
        }
        public IActionResult AddToFavourites(int fld_offeredserviceid)
        {
            CookieOptions options = new CookieOptions();

            options.Expires = DateTime.Now.AddSeconds(200);

            //De message die we de user geven gaat afhangen van de volgende try catch blokken:

            try
            {
                //De key voor de cookie
                string currentKey = "FL" + fld_offeredserviceid;
                //Check eerst of de service al in de favorites zit
                int sameKey = Request.Cookies.Keys.Count(k => k.Equals(currentKey));
                if (sameKey > 0)
                {
                    //Service zit al in favorites. Doe niets
                    ViewBag.FLResultMessage = "<p>Again?</p>";
                    return(View());
                }
                //Service zit nog niet in favorites
                Response.Cookies.Append(currentKey, "1", options);
                //Response.WriteAsync("<script>alert('test')</script>");

                ViewBag.FLResultMessage = "<p>Success!</p>";

                //Update the OLS in ElasticSearch
                OfferedLabourerService ols = EsOLSQuery <OfferedLabourerService> .findByOfferedServiceId(fld_offeredserviceid);

                ols.fld_addedtowishlist = ols.fld_addedtowishlist + 1;

                //Because ElasticSearch does not support decimal numbers, we must multiply the cost by a 100
                ols.fld_cost = ols.fld_cost * 100;
                ElasticSearch.EsUpdater <OfferedLabourerService> .UpsertDocument(ols, "moll_ols", "OLS", fld_offeredserviceid);

                return(View());
            }
            catch (Exception e)
            {
                ViewBag.FLResultMessage = "<p>Success!</p>";

                return(View());
            }
        }
        public List <OfferedLabourerService> ParseOrdersToOLS()
        {
            //Add exception handler!
            string orders    = this.HttpContext.Session.GetString("ORD").Substring(1);
            char   separator = ' ';

            string[] orderIds = orders.Split(separator);

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

            double cost = olsList.Sum(s => s.fld_cost);

            foreach (string id in orderIds)
            {
                int olsId = Convert.ToInt32(id);
                olsList.Add(EsOLSQuery <OfferedLabourerService> .findByOfferedServiceId(olsId));
            }
            return(olsList);
        }
        public IActionResult HomePage()
        {
            //We greet the user with services

            //The 5 most popular
            List <OfferedLabourerService> mostPopular = EsOLSQuery <Object> .mostFavourited();

            //The 5 cheapest
            List <OfferedLabourerService> cheapest = EsOLSQuery <Object> .Cheapest();

            //The 5 Most Bought
            List <OfferedLabourerService> mostBought = EsOLSQuery <Object> .mostBought();

            //5 services from a random category
            //First, create the procedure and method for getting all distinct categories

            Tuple <List <OfferedLabourerService>, List <OfferedLabourerService>, List <OfferedLabourerService> > homePageModel = Tuple.Create(mostPopular, cheapest, mostBought);

            return(View(homePageModel));
            //5 Services from a random category
        }
        public IActionResult SimpleSearch(string simpleQuery)
        {
            List <OfferedLabourerService> newPackage = EsOLSQuery <OfferedLabourerService> .simpleSearch(simpleQuery);

            return(View("Search", newPackage));
        }
        public IActionResult ManageOLS()
        {
            List <OfferedLabourerService> allOLS = EsOLSQuery <OfferedLabourerService> .getAll();

            return(View(allOLS));
        }
        public int EditItem(string insertedDic, string type)
        {
            switch (type)
            {
            case "tbl_userdata":
                try
                {
                    tbl_userdata currentUser = JsonConvert.DeserializeObject <tbl_userdata>(insertedDic);

                    //Dates and ElasticSearch do not mix very well, so we do a little check beforehand
                    if (currentUser.fld_dateofbirth == "")
                    {
                        currentUser.fld_dateofbirth = null;
                    }

                    EsUpdater <tbl_userdata> .UpsertDocument(currentUser, "moll_users", "User", currentUser.fld_userid);

                    MollShopContext.UpdateRow(currentUser, "fld_UserId", currentUser.fld_userid);
                }
                catch (Exception e)
                {
                    return(-1);
                }

                break;

            case "tbl_servicedata":
                tbl_servicedata currentService = JsonConvert.DeserializeObject <tbl_servicedata>(insertedDic);

                //Update the stand-alone service document
                EsUpdater <tbl_servicedata> .UpsertDocument(currentService, "moll_dataservices", "Services", currentService.fld_serviceid);

                //Find all OLS documents in ES that contain this service
                List <OfferedLabourerService> packages = EsOLSQuery <OfferedLabourerService> .getByService(currentService.fld_serviceid);

                //Foreach OLS ID, update it with the current service
                foreach (OfferedLabourerService package in packages)
                {
                    package.fld_name        = currentService.fld_name;
                    package.fld_category    = currentService.fld_category;
                    package.fld_description = currentService.fld_description;
                    package.fld_imagelink   = currentService.fld_imagelink;

                    EsUpdater <OfferedLabourerService> .UpsertDocument(package, "moll_ols", "OLS", package.fld_offeredserviceid);
                }

                MollShopContext.UpdateRow(currentService, "fld_ServiceId", currentService.fld_serviceid);

                break;

            case "tbl_labourerdata":
                tbl_labourerdata currentLabourer = JsonConvert.DeserializeObject <tbl_labourerdata>(insertedDic);

                //Update the stand-alone labourer document
                EsUpdater <tbl_labourerdata> .UpsertDocument(currentLabourer, "moll_labourers", "Labourer", currentLabourer.fld_labourerid);

                //Find all OLS documents in ES that contain this labourer
                List <OfferedLabourerService> olspackages = EsOLSQuery <OfferedLabourerService> .getByLabourer(currentLabourer.fld_labourerid);

                //Foreach OLS Id, update it with the current labourer
                foreach (OfferedLabourerService package in olspackages)
                {
                    package.fld_address     = currentLabourer.fld_address;
                    package.fld_firstname   = currentLabourer.fld_firstname;
                    package.fld_email       = currentLabourer.fld_email;
                    package.fld_gender      = currentLabourer.fld_gender;
                    package.fld_lastname    = currentLabourer.fld_lastname;
                    package.fld_phonenumber = currentLabourer.fld_phonenumber;
                    package.fld_zipcode     = currentLabourer.fld_zipcode;

                    EsUpdater <OfferedLabourerService> .UpsertDocument(package, "moll_ols", "OLS", package.fld_offeredserviceid);
                }

                MollShopContext.UpdateRow(currentLabourer, "fld_LabourerId", currentLabourer.fld_labourerid);

                break;

            default:
                break;
            }

            return(1);
        }