<%@ Page language="c#" Debug="true"%><!--#include file="SchoolsWShared.aspx"--><%
//! Support file only, run SchoolsW.html instead !
// This file is used as target of custom AJAX call in SchoolsW.html
// Saves Review to database

// --- Database initialization ---
TGSchools TG = new TGSchools(Context);

if (Request["id"] != null)
{
   // --- Reads input parameters ---
   string[] id = Request["id"].Split("$".ToCharArray()); // User$Def$Ident
   string Text = Request["Text"];
   string Stars = Request["Stars"];

   // --- Saves Review to database ---
   TG.Copy();
   TG.Exec("INSERT INTO Schools_Ratings(Owner,Id,Stars,Review,ADate) VALUES (" + ToSql(id[0]) + "," + id[2] + "," +Stars + "," + ToSql(Text) + ",'" + DateTime.Now.ToString("M/d/yyyy") + "')");
   TG.Exec("UPDATE Schools_Schools SET RatingSum=RatingSum+"+Stars+", RatingCnt=RatingCnt+1 WHERE Owner=" + ToSql(id[0]) + " AND Id=" + id[2]);  
}
Response.Write ("<Grid><IO Result='0' Message='Your review was successfully added'/></Grid>");
TG.Dispose();
// --------------------------------------------------------------------------
%>