protected void rateConfirmButton_Click1(object sender, EventArgs e) { TrainerRatingFactory trainerRatingFactory = new TrainerRatingFactory(); TrainerRatingGateway <TrainerRating> tr = (TrainerRatingGateway <TrainerRating>)trainerRatingFactory.GetTrainerRating(); decimal temp; TrainerRating rating = new TrainerRating(); rating.TrainerId = trainers[trainerDropdownId.SelectedIndex].RecordId; System.Diagnostics.Debug.WriteLine("bu:" + trainerDropdownId.SelectedIndex); rating.RatingNumber = (decimal.TryParse(starNumbers[trainerStars.SelectedIndex], out temp) ? temp : 0M); rating.Text = ratingText.Text; rating.ClientId = int.Parse(Session["ID"].ToString());; if (string.IsNullOrWhiteSpace(ratingText.Text)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please, fill in rating text');window.location ='TrainerRate.aspx';", true); } else { tr.Insert(rating); Session["rated"] = "rated"; Session["ratedTrainer"] = trainers[trainerDropdownId.SelectedIndex].Name + " " + trainers[trainerDropdownId.SelectedIndex].Surname; Session["ratedTrainerID"] = trainers[trainerDropdownId.SelectedIndex].RecordId; Response.Redirect("~/TrainerRate.aspx"); } }
private void PrepareCommand(SqlCommand command, TrainerRating rating) { command.Parameters.AddWithValue("@text", rating.Text); command.Parameters.AddWithValue("@rating_number", rating.RatingNumber); command.Parameters.AddWithValue("@client_id", rating.ClientId); command.Parameters.AddWithValue("@trainer_id", rating.TrainerId); }
public XElement Insert(TrainerRating rating) { XElement result = new XElement("TrainerRating", new XAttribute("Id", rating.RecordId), new XAttribute("Text", rating.Text), new XAttribute("RatingNumber", rating.RatingNumber.ToString()), new XAttribute("ClientId", rating.ClientId), new XAttribute("TrainerId", rating.TrainerId)); return(result); }
private Collection <T> Read(SqlDataReader reader) { Collection <T> ratings = new Collection <T>(); while (reader.Read()) { TrainerRating rating = new TrainerRating(); int i = -1; rating.RecordId = reader.GetInt32(++i); rating.Text = reader.GetString(++i); rating.RatingNumber = reader.GetDecimal(++i); rating.ClientId = reader.GetInt32(++i); rating.TrainerId = reader.GetInt32(++i); ratings.Add((T)rating); } return(ratings); }
public Collection <T> Select() { XDocument xDoc = XDocument.Load(Paths.FilePath); List <XElement> elements = xDoc.Descendants("TrainerRatings").Descendants("TrainerRating").ToList(); Collection <T> ratings = new Collection <T>(); foreach (var element in elements) { TrainerRating rating = new TrainerRating() { ClientId = int.Parse(element.Attribute("ClientId").Value), TrainerId = int.Parse(element.Attribute("TrainerId").Value), RatingNumber = decimal.Parse(element.Attribute("RatingNumber").Value), Text = element.Attribute("Text").Value }; ratings.Add((T)rating); } return(ratings); }