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");
            }
        }
Example #2
0
 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);
 }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }