//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 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); }