/// <summary> /// Print the object's XML to the XmlWriter. /// </summary> /// <param name="objWriter">XmlTextWriter to write with.</param> /// <param name="objCulture">Culture in which to print.</param> /// <param name="strLanguageToPrint">Language in which to print</param> public void Print(XmlTextWriter objWriter, CultureInfo objCulture, string strLanguageToPrint) { objWriter.WriteStartElement("power"); objWriter.WriteElementString("name", DisplayNameShort(strLanguageToPrint)); objWriter.WriteElementString("fullname", DisplayName); objWriter.WriteElementString("extra", LanguageManager.TranslateExtra(Extra, strLanguageToPrint)); objWriter.WriteElementString("pointsperlevel", PointsPerLevel.ToString(objCulture)); objWriter.WriteElementString("adeptway", AdeptWayDiscount.ToString(objCulture)); objWriter.WriteElementString("rating", LevelsEnabled ? TotalRating.ToString(objCulture) : "0"); objWriter.WriteElementString("totalpoints", PowerPoints.ToString(objCulture)); objWriter.WriteElementString("action", DisplayActionMethod(strLanguageToPrint)); objWriter.WriteElementString("source", CommonFunctions.LanguageBookShort(Source, strLanguageToPrint)); objWriter.WriteElementString("page", DisplayPage(strLanguageToPrint)); if (CharacterObject.Options.PrintNotes) { objWriter.WriteElementString("notes", Notes); } objWriter.WriteStartElement("enhancements"); foreach (Enhancement objEnhancement in Enhancements) { objEnhancement.Print(objWriter, strLanguageToPrint); } objWriter.WriteEndElement(); objWriter.WriteEndElement(); }
public void CalcAvgRatingTestPass() { var model = new TotalRating(); double totalRatings = 15; double totalRaters = 4; double result = model.calcAvgRating(totalRatings, totalRaters); Assert.AreEqual(3.75, result); }
public void CalcAvgRatingTestFail() { var model = new TotalRating(); double totalRatings = 15; double totalRaters = 4; double result = model.calcAvgRating(totalRatings, totalRaters); Assert.AreNotEqual(22, result); }
public async Task <ActionResult> Create(string id, [Bind(Include = "RatingID,Ratings,KennelID,Comment,RatingDate")] Rating rating) { var currentUser = getUser(); if (ModelState.IsValid) { bool totalRatingExists = db.TotalRating.Where(k => k.KennelID == id).Count() > 0; //if the kennel has never been rated it will add an initial rating if (totalRatingExists == false) { var newTRate = new TotalRating() { KennelID = id, TotalRatings = rating.Ratings, TotalRaters = 1, AverageRating = rating.Ratings }; db.TotalRating.Add(newTRate); await db.SaveChangesAsync(); } //if the kennel has been rated previously (by any user) it will update the existing entry. else { //Adds 1 to total Raters on the TotalRatings table where the KennelId match those of the rating. //Adds the rating to the TotalRatings. //Updates AverageRating var tra = db.TotalRating.Where(r => r.KennelID == id).First(); tra.TotalRaters += 1; tra.TotalRatings += rating.Ratings; tra.AverageRating = tra.calcAvgRating(tra.TotalRatings, tra.TotalRaters); db.Entry(tra).State = EntityState.Modified; await db.SaveChangesAsync(); } rating.RatingDate = DateTime.Now; rating.User = currentUser; rating.KennelID = id; db.Rating.Add(rating); await db.SaveChangesAsync(); TempData["Thank"] = "Thank you for your rating"; return(RedirectToAction("Index")); } return(View(rating)); }