public List <DTO_CORE_Gig> CreateGig(DTO_CORE_Gig request) { using (DB_connection context = new GigALoan_DAL.DB_connection()) { CORE_Gigs newgig = new CORE_Gigs { AlertID = request.AlertID, StudentID = request.StudentID, ClientComments = request.ClientComments, StudentRating = 0, ClientRating = 0 }; if (context.CORE_GigAlerts.Where(ga => ga.AlertID == request.AlertID).Single().Active == true) { context.CORE_Gigs.Add(newgig); var alert = (from a in context.CORE_GigAlerts where a.AlertID == request.AlertID select a).Single(); alert.Active = false; context.SaveChanges(); } //string insertString = "IF ((SELECT Active FROM CORE_GigAlerts WHERE AlertID = " + request.AlertID + ") = 1) " + // "INSERT INTO CORE_Gigs(AlertID, DateAccepted, StudentID, ClientComments, StudentRating, ClientRating) VALUES(" + // request.AlertID + ", " + request.DateAccepted.ToString("yyyy-mm-dd") + ", " + request.StudentID + ", '" + request.ClientComments + "', 0, 0) " + // "UPDATE CORE_GigAlerts SET Active = 0 FROM CORE_GigAlerts WHERE AlertID = " + request.AlertID; //SqlConnection connection = new SqlConnection(); //connection.ConnectionString = "Server=tcp:s05.winhost.com;Database=DB_42039_gig;User ID=DB_42039_gig_user;Password=gigaloan"; //SqlCommand cmd = new SqlCommand(insertString, connection); //connection.Open(); //cmd.ExecuteNonQuery(); //connection.Close(); //var result = context.CORE_Gigs.Where(g => g.AlertID == request.AlertID).Single(); DTO_CORE_Gig gigToBeReturned = new DTO_CORE_Gig { AlertID = newgig.AlertID, ClientComments = newgig.ClientComments, ClientRating = 0.0, DateAccepted = newgig.DateAccepted, DateClosed = Convert.ToDateTime(null), GigID = newgig.GigID, StudentComments = "", StudentID = newgig.StudentID, StudentRating = 0.0 }; var returnObject = new List <DTO_CORE_Gig>(); returnObject.Add(gigToBeReturned); return(returnObject); } }
public List <DTO_CORE_Gig> CreateGig(DTO_CORE_Gig request) { GigALoan_DAL.DB_connection context = new GigALoan_DAL.DB_connection(); string insertString = "IF ((SELECT Active FROM CORE_GigAlerts WHERE AlertID = " + request.AlertID + ") = 1) " + "INSERT INTO CORE_Gigs(AlertID, DateAccepted, StudentID, ClientComments, StudentRating, ClientRating) VALUES(" + request.AlertID + ", " + request.DateAccepted.ToString("yyyy-mm-dd") + ", " + request.StudentID + ", '" + request.ClientComments + "', 0, 0) " + "UPDATE CORE_GigAlerts SET Active = 0 FROM CORE_GigAlerts WHERE AlertID = " + request.AlertID; SqlConnection connection = new SqlConnection(); connection.ConnectionString = "Server=tcp:s05.winhost.com;Database=DB_42039_gig;User ID=DB_42039_gig_user;Password=gigaloan"; SqlCommand cmd = new SqlCommand(insertString, connection); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); var result = context.CORE_Gigs.Where(g => g.AlertID == request.AlertID).Single(); DTO_CORE_Gig gigToBeReturned = new DTO_CORE_Gig { AlertID = result.AlertID, ClientComments = result.ClientComments, ClientRating = 0.0, DateAccepted = result.DateAccepted, DateClosed = Convert.ToDateTime(null), GigID = result.GigID, StudentComments = "", StudentID = result.StudentID, StudentRating = 0.0 }; var returnObject = new List <DTO_CORE_Gig>(); returnObject.Add(gigToBeReturned); return(returnObject); }
public List <DTO_CORE_Gig> FindGigsByClientID(DTO_CORE_Client request) { List <DTO_CORE_Gig> results = new List <DTO_CORE_Gig>(); using (DB_connection context = new GigALoan_DAL.DB_connection()) { var gigList = context.CORE_Gigs.Where(g => g.CORE_GigAlerts.ClientID == request.ClientID); foreach (CORE_Gigs gig in gigList) { DTO_CORE_Gig result = new DTO_CORE_Gig { GigID = gig.GigID, StudentID = gig.StudentID, AlertID = gig.AlertID, DateAccepted = gig.DateAccepted, StudentComments = gig.StudentComments, ClientComments = gig.ClientComments }; if (gig.DateClosed != null) { result.DateClosed = (DateTime)gig.DateClosed; } if (gig.StudentRating != null) { result.StudentRating = (double)gig.StudentRating; } if (gig.ClientRating != null) { result.ClientRating = (double)gig.ClientRating; } results.Add(result); } return(results); } }