protected void Record_Click(object sender, EventArgs e) { int total = int.Parse(Front9Total.Text) + int.Parse(Back9Total.Text); Score NewScore = new Score(TeeList.SelectedValue, total); foreach (TextBox item in boxes) { try { NewScore.scores.Add(int.Parse(item.Text)); } catch (Exception) { Message.Text = "Your scores are not correct"; } } if (NewScore.scores.Count == 18) { NewScore.HandicapDifferential = Math.Round(((NewScore.Total - float.Parse(Rating.Text)) * 113) / float.Parse(Slope.Text), 1); } ClubBAISTRequestDirector CBRD = new ClubBAISTRequestDirector(); if (CBRD.RecordScore((int)Session["MemberNumber"], NewScore)) { Message.Text = "Score was recorded successfully"; } else { Message.Text = "There seems to be an error in your score."; } }
public JsonResult RecordTee(string totalAndTee) { string message = string.Empty; bool status = false; try { var response = JsonConvert.DeserializeObject <RecordPlayerScoreResponse>(totalAndTee); boxes = new List <string>() { "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10", "S11", "S12", "S13", "S14", "S15", "S16", "S17", "S18" }; Score NewScore = new Score(response.teeValue, response.total); for (int i = 0; i < boxes.Count; i++) { NewScore.scores.Add(int.Parse(boxes[i].Last().ToString())); } if (NewScore.scores.Count == 18) { //NewScore.HandicapDifferential = Math.Round(((NewScore.Total - float.Parse(response.rating)) * 113) / float.Parse(response.slope), 1); NewScore.HandicapDifferential = Math.Round(((NewScore.Total - (!string.IsNullOrEmpty(response.rating) ? float.Parse(response.rating) : 0)) * 113) / (!string.IsNullOrEmpty(response.slope) ? float.Parse(response.slope) : 0), 1); } ClubBAISTRequestDirector CBRD = new ClubBAISTRequestDirector(); if (CBRD.RecordScore((int)Session["MemberNumber"], NewScore)) { message = "Score was recorded successfully"; } else { message = "There seems to be an error in your score."; } } catch (Exception ex) { status = false; message = ex.Message.ToString(); return(Json(new { status = status, message = message }, JsonRequestBehavior.AllowGet)); } return(Json(new { status = status, message = message }, JsonRequestBehavior.AllowGet)); }