/// <summary> /// Retrieves and returns a client planet by requesting from the server /// </summary> public static async Task <ClientPlanet> GetClientPlanetAsync(ulong id) { string json = await ClientUserManager.Http.GetStringAsync($"Planet/GetPlanet?planet_id={id}&auth={ClientUserManager.UserSecretToken}"); TaskResult <ClientPlanet> result = JsonConvert.DeserializeObject <TaskResult <ClientPlanet> >(json); if (result == null) { Console.WriteLine("A fatal error occurred retrieving a planet from the server."); return(null); } if (!result.Success) { Console.WriteLine(result.ToString()); return(null); } return(result.Data); }
/// <summary> /// Retrieves and returns categories of a planet by requesting from the server /// </summary> public async Task <IEnumerable <PlanetCategory> > GetClientPlanetCategoriesAsync(ulong id) { string json = await ClientUserManager.Http.GetStringAsync($"Category/GetPlanetCategories?planet_id={id}"); TaskResult <IEnumerable <PlanetCategory> > result = JsonConvert.DeserializeObject <TaskResult <IEnumerable <PlanetCategory> > >(json); if (result == null) { Console.WriteLine("A fatal error occurred retrieving a planet from the server."); return(null); } if (!result.Success) { Console.WriteLine(result.ToString()); return(null); } return(result.Data); }
public static ActionResult ToActionResult(this TaskResult result) { switch (result) { case TaskResult.Succeeded: return(ActionResult.Success); case TaskResult.Failed: return(ActionResult.Failure); case TaskResult.Canceled: return(ActionResult.Cancelled); case TaskResult.Skipped: return(ActionResult.Skipped); default: throw new NotSupportedException(result.ToString()); } }
/// <summary> /// Loads the user into cache, or reloads them if called again /// </summary> /// <returns></returns> public async Task LoadUserAsync() { string json = await ClientUserManager.Http.GetStringAsync($"User/GetUser?id={User_Id}"); TaskResult <User> result = JsonConvert.DeserializeObject <TaskResult <User> >(json); if (result == null) { Console.WriteLine("A fatal error occurred retrieving a user from the server."); return; } if (!result.Success) { Console.WriteLine(result.ToString()); return; } _user = result.Data; }
/// <summary> /// Loads the user roles into cache, or reloads them if called again /// </summary> public async Task LoadRolesAsync() { string json = await ClientUserManager.Http.GetStringAsync($"Planet/GetPlanetMemberRoleIds?user_id={User_Id}&planet_id={Planet_Id}&token={ClientUserManager.UserSecretToken}"); Console.WriteLine(json); TaskResult <List <ulong> > result = JsonConvert.DeserializeObject <TaskResult <List <ulong> > >(json); if (result == null) { Console.WriteLine("A fatal error occurred retrieving planet user roles from the server."); } if (!result.Success) { Console.WriteLine(result.ToString()); Console.WriteLine($"Failed for {Id} in {Planet_Id}"); } _roleids = result.Data; }
private string UpdateBeachCampEvent(TaskResult status) { string output = string.Empty; try { if (string.IsNullOrEmpty(lblError.Text) && lblError.Visible) return lblError.Text; string sectionPeriod = string.Empty; double totalPrice = 0; if (string.IsNullOrEmpty(txtEventDate.Text)) return Constants.ERROR_MESSAGE; string[] eventDateArray = txtEventDate.Text.Split('/'); DateTime beachCampDate = new DateTime(int.Parse(eventDateArray[2]), int.Parse(eventDateArray[1]), int.Parse(eventDateArray[0])); //DateTime.Parse(ffEventDate.Value.ToString()); SPFieldUserValue userValue = new SPFieldUserValue(SPContext.Current.Web, SPContext.Current.ListItem[SPBuiltInFieldId.Author].ToString()); bool isReserved = BeachCampHelper.IsUserReserved(SPContext.Current.Web, userValue.User.ID.ToString(), beachCampDate, SPContext.Current.ItemId); if (isReserved) return Constants.ERROR_MESSAGE1;//return "You can only reserve beach camp one a month. Please select another day!"; foreach (RepeaterItem prices in repeaterPrices.Items) { CheckBox chkPeriod1 = (CheckBox)prices.FindControl("chkPeriod1"); if (chkPeriod1 != null && chkPeriod1.Checked) { sectionPeriod += chkPeriod1.ToolTip + "|"; totalPrice += double.Parse(chkPeriod1.Text.Split(' ')[0]); } CheckBox chkPediod2 = (CheckBox)prices.FindControl("chkPeriod2"); if (chkPediod2 != null && chkPediod2.Checked) { sectionPeriod += chkPediod2.ToolTip + "|"; totalPrice += double.Parse(chkPediod2.Text.Split(' ')[0]); } CheckBox chkFullDay = (CheckBox)prices.FindControl("chkFullDay"); if (chkFullDay != null && chkFullDay.Checked) { sectionPeriod += chkFullDay.ToolTip + "|"; totalPrice += double.Parse(chkFullDay.Text.Split(' ')[0]); } CheckBox chkRamadan = (CheckBox)prices.FindControl("chkRamadan"); if (chkRamadan != null && chkRamadan.Checked) { sectionPeriod += chkRamadan.ToolTip + "|"; totalPrice += double.Parse(chkRamadan.Text.Split(' ')[0]); } } if (string.IsNullOrEmpty(sectionPeriod)) return Constants.ERROR_MESSAGE3;//return "Please choose a Section and Period !"; sectionPeriod = sectionPeriod.TrimEnd('|'); string sectionPeriodReserved = CheckReverseSection(sectionPeriod); if (!string.IsNullOrEmpty(sectionPeriodReserved)) return sectionPeriodReserved;//"This section and period is reserved. Please choose another section - period !"; string typeOfBeachCamp = rdbPersonal.Text; if (rdbBusiness.Checked) typeOfBeachCamp = rdbBusiness.Text; //totalPrice = totalPrice * int.Parse(ffRequireDay.Value.ToString()); SPListItem item = SPContext.Current.ListItem; item[SPBuiltInFieldId.Title] = ffTitle.Value; item["TypeOfBeachCamp"] = typeOfBeachCamp; item["EmployeeCode"] = ffEmployeeCode.Value; item["Department"] = ffDepartment.Value; item["Section"] = ffSection.Value; item["OfficeTel"] = ffOfficeTel.Value; item["Mobile"] = ffMobile.Value; item[SPBuiltInFieldId.StartDate] = beachCampDate; item[SPBuiltInFieldId.EndDate] = beachCampDate;//beachCampDate.AddDays(int.Parse(ffRequireDay.Value.ToString())); item["Reason"] = ffReason.Value; //item["RequireDay"] = ffRequireDay.Value; item["TotalPrice"] = totalPrice; item[SPBuiltInFieldId.Location] = sectionPeriod; item["GSApproval"] = status.ToString(); item.Update(); } catch (Exception ex) { Utility.LogError(ex.Message, BeachCampFeatures.BeachCamp); output = ex.Message; } return output; }
private void WriteTaskAndTreadInfo(int threadId, TaskResult taskResult) { Console.WriteLine($"Thread{threadId} - Start parent task with {taskResult.ToString()}"); }