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 static string RegisterNewUser(tbl_userdata user) { string activationCode = generateActivationCode(); try { Dictionary <string, Object> dic = new Dictionary <string, Object>(); dic.Add("in_userName", user.fld_username); dic.Add("in_password", SaltNHash(user.fld_password)); dic.Add("in_firstName", user.fld_firstname); dic.Add("in_lastName", user.fld_lastname); dic.Add("in_gender", user.fld_gender); dic.Add("in_address", user.fld_address); dic.Add("in_zipCode", user.fld_zipcode); dic.Add("in_dob", user.fld_dateofbirth); dic.Add("in_phoneNumber", user.fld_phonenumber); dic.Add("in_emailAddress", user.fld_email); dic.Add("in_activationCode", activationCode); dic.Add("in_isActivated", false); dic.Add("out_userId", 0); dic = ProcedureCall <int> .ExecuteNonQuery(dic, "user_Register"); user.fld_activationcode = activationCode; user.fld_userid = Convert.ToInt32(dic["out_userId"]); EsUpdater <tbl_userdata> .InsertDocument(user, "moll_users", "User", dic["out_userId"].ToString()); return(activationCode); } catch (Exception e) { return("Db Error!"); } }
public int CreateItem(string insertedDic, string type) { //return the id back to the JS Datatable! switch (type) { case "tbl_userdata": tbl_userdata newUser = JsonConvert.DeserializeObject <tbl_userdata>(insertedDic); //Check if the email has been taken already int emailIsTaken = MollShopContext.CheckIfUserExists(newUser.fld_email); if (emailIsTaken == 0) { //Email has not yet been taken //Salt and Hash the password newUser.fld_password = MollShopContext.SaltNHash(newUser.fld_password); newUser.fld_userid = MollShopContext.CreateRow(newUser, type); if (newUser.fld_dateofbirth == "") { newUser.fld_dateofbirth = null; } EsUpdater <tbl_userdata> .InsertDocument(newUser, "moll_users", "User", newUser.fld_userid.ToString()); return(newUser.fld_userid); } else { //Email has been taken return(-1); } case "tbl_servicedata": tbl_servicedata newService = JsonConvert.DeserializeObject <tbl_servicedata>(insertedDic); newService.fld_serviceid = MollShopContext.CreateRow(newService, type); EsUpdater <tbl_servicedata> .InsertDocument(newService, "moll_dataservices", "Services", newService.fld_serviceid.ToString()); return(newService.fld_serviceid); case "tbl_labourerdata": tbl_labourerdata newLabourer = JsonConvert.DeserializeObject <tbl_labourerdata>(insertedDic); newLabourer.fld_labourerid = MollShopContext.CreateRow(newLabourer, type); EsUpdater <tbl_labourerdata> .InsertDocument(newLabourer, "moll_labourers", "Labourer", newLabourer.fld_labourerid.ToString()); return(newLabourer.fld_labourerid); default: break; } return(0); }
public static int VerifyUser(string token, int userid) { int result = 0; try { Dictionary <string, Object> dic = new Dictionary <string, Object>(); dic.Add("in_token", token); dic.Add("in_userid", userid); dic.Add("out_result", result); dic = ProcedureCall <int> .ExecuteNonQuery(dic, "user_verify"); EsUpdater <tbl_userdata> .UpdateField("" + userid, "fld_isactivated", 1); return(Convert.ToInt32(dic["out_result"])); } catch (Exception e) { return(result); } }
public IActionResult DeleteItem(int id, string type) { switch (type) { case "tbl_userdata": MollShopContext.DeleteRow(type, "fld_UserId", id); EsUpdater <tbl_userdata> .DeleteDocument(id, "User", "moll_users"); break; case "tbl_servicedata": MollShopContext.DeleteRow(type, "fld_serviceid", id); EsUpdater <tbl_servicedata> .DeleteDocument(id, "Services", "moll_dataservices"); break; case "tbl_labourerdata": MollShopContext.DeleteRow(type, "fld_labourerid", id); EsUpdater <tbl_labourerdata> .DeleteDocument(id, "Labourer", "moll_labourers"); //Delete the OLS for this labourer as well break; case "offeredlabourerservice": MollShopContext.DeleteRow("tbl_offeredservicesdata", "fld_offeredServiceId", id); EsUpdater <OfferedLabourerService> .DeleteDocument(id, "OLS", "moll_ols"); break; default: break; } return(Ok()); }
public OLS CreateOLS(string offeredService, string serviceId, string labourerId) { tbl_servicedata service = EsServiceQuery.FindById(Convert.ToInt32(serviceId)); tbl_labourerdata labourer = EsLabourerQuery.FindById(Convert.ToInt32(labourerId)); tbl_offeredservicesdata offeredServiceObj = JsonConvert.DeserializeObject <tbl_offeredservicesdata>(offeredService); offeredServiceObj.fld_labourerid = labourer.fld_labourerid; offeredServiceObj.fld_serviceid = service.fld_serviceid; offeredServiceObj.fld_offeredserviceid = MollShopContext.CreateRow(offeredServiceObj, "tbl_offeredservicesdata"); OLS ols = ConstructOLS(service, labourer, offeredServiceObj); //Because ElasticSearch does not support decimal numbers, we must multiply the cost by a 100 ols.fld_cost = ols.fld_cost * 100; EsUpdater <OLS> .InsertDocument(ols, "moll_ols", "OLS", ols.fld_offeredserviceid.ToString()); //return the OfferedLabourerService, so we can later render it into the Datatable on the ManageOLS page //We must divide the cost by a 100 again, to render it correctly ols.fld_cost = ols.fld_cost / 100; return(ols); }
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); }
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")); }