private void detach_ProdInstallationBuffets(ProdInstallationBuffet entity)
		{
			this.SendPropertyChanging();
			entity.ProjectInformation = null;
		}
 partial void DeleteProdInstallationBuffet(ProdInstallationBuffet instance);
 partial void UpdateProdInstallationBuffet(ProdInstallationBuffet instance);
 partial void InsertProdInstallationBuffet(ProdInstallationBuffet instance);
        public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db)
        {
            System.IO.StreamReader reader = new System.IO.StreamReader(context.Request.InputStream, context.Request.ContentEncoding);

            var jsonSerializer = new JsonSerializer();
            JObject blob = (JObject)jsonSerializer.Deserialize(new JsonTextReader(new StringReader(reader.ReadToEnd())));

            string filter = context.Request.Params.Get("project_id");

            if (!isNull(filter))
            {
                try
                {
                    //check to see if there already is a prod installation buffet entry with this project id
                    if (db.ProdInstallationBuffets.Count(a => a.project_id.Equals(int.Parse(filter))) > 0)
                    {
                        var wiping = db.ProdInstallationBuffets.Where(a => a.project_id.Equals(int.Parse(filter)));
                        db.ProdInstallationBuffets.DeleteAllOnSubmit(wiping);
                        db.SubmitChanges();
                    }
                    

                    ProdInstallationBuffet newEntry = new ProdInstallationBuffet();
                    newEntry.project_id = int.Parse(filter);
                    if (blob["viewBuffetProdInstallDate"] != null)
                    {
                        newEntry.date = (string)blob["viewBuffetProdInstallDate"];
                    }
                    if (blob["viewBuffetProdInstallConferenceStart"] != null)
                    {
                        newEntry.conference_start = (string)blob["viewBuffetProdInstallConferenceStart"];
                    }
                    if (blob["viewBuffetProdInstallConferenceBridge"] != null)
                    {
                        newEntry.conference_bridge = (string)blob["viewBuffetProdInstallConferenceBridge"];
                    }
                    if (blob["buffetprodinstallNodes"] != null)
                    {
                        if (blob["buffetprodinstallNodes"].Type.ToString().Equals("String"))
                        {
                            newEntry.nodes = (string)blob["buffetprodinstallNodes"];
                        }
                        else
                        {
                            JArray nodes = (JArray)blob["buffetprodinstallNodes"];
                            if (nodes.Count > 0)
                            {
                                for (int i = 0; i < blob["buffetprodinstallNodes"].Count(); i++)
                                {
                                    newEntry.nodes += (string)blob["buffetprodinstallNodes"][i] + ", ";
                                }
                                newEntry.nodes = newEntry.nodes.Substring(0, newEntry.nodes.Length - 2);
                            }
                        }
                    }
                    if (blob["buffetprodinstallComments"] != null)
                    {
                        newEntry.comments = (string)blob["buffetprodinstallComments"];
                    }
                    if (blob["viewBuffetProdInstallPostMaintenanceMasterProject"] != null)
                    {
                        if (blob["viewBuffetProdInstallPostMaintenanceMasterProject"].Type.ToString().Equals("String"))
                        {
                            //SINGLE INSTANCE
                            newEntry.post_maintenance_notification = (string)blob["viewBuffetProdInstallPostMaintenanceMasterProject"];
                        }
                        else
                        {
                            //ARRAY OF EMAILS
                            JArray emails = (JArray)blob["viewBuffetProdInstallPostMaintenanceMasterProject"];
                            if (emails.Count > 0)
                            {
                                for (int i = 0; i < emails.Count; i++)
                                {
                                    newEntry.post_maintenance_notification += (string)emails[i] + "; ";
                                }
                                newEntry.post_maintenance_notification = newEntry.post_maintenance_notification.Substring(0, newEntry.post_maintenance_notification.Length - 2);
                            }
                        }
                    }
                    db.ProdInstallationBuffets.InsertOnSubmit(newEntry);
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    return new PagedData("Error: " + e.Message + e.Source + e.StackTrace + e.TargetSite + e.InnerException + e.HelpLink);
                }

                try
                {
                    //Staging Folders
                    if (blob["buffetProdInstallStagingFolderLink"] != null)
                    {
                        var wipingStaging = db.StagingFolders.Where(a => a.project_id.Equals(int.Parse(filter)) && a.is_buffet.Equals(true));
                        db.StagingFolders.DeleteAllOnSubmit(wipingStaging);
                        db.SubmitChanges();

                        if (blob["buffetProdInstallStagingFolderLink"].Type.ToString().Equals("String"))
                        {
                            StagingFolder newStagingEntry = new StagingFolder();
                            newStagingEntry.project_id = int.Parse(filter);
                            newStagingEntry.is_buffet = true;
                            newStagingEntry.folder = (string)blob["buffetProdInstallStagingFolderLink"];
                            if (blob["buffetProdInstallStagingNotes"] != null)
                            {
                                newStagingEntry.notes = (string)blob["buffetProdInstallStagingNotes"];
                            }
                            db.StagingFolders.InsertOnSubmit(newStagingEntry);
                            db.SubmitChanges();
                        }
                        else
                        {
                            for (int i = 0; i < blob["buffetProdInstallStagingFolderLink"].Count(); i++)
                            {
                                StagingFolder newStagingEntry = new StagingFolder();
                                newStagingEntry.project_id = int.Parse(filter);
                                newStagingEntry.is_buffet = true;
                                newStagingEntry.folder = (string)blob["buffetProdInstallStagingFolderLink"][i];
                                if (blob["buffetProdInstallStagingNotes"][i] != null)
                                {
                                    newStagingEntry.notes = (string)blob["buffetProdInstallStagingNotes"][i];
                                }
                                db.StagingFolders.InsertOnSubmit(newStagingEntry);
                            }
                            db.SubmitChanges();
                        }
                    }
                    else
                    {
                        try
                        {
                            var wipingStaging = db.StagingFolders.Where(a => a.project_id.Equals(int.Parse(filter)) && a.is_buffet.Equals(true));
                            db.StagingFolders.DeleteAllOnSubmit(wipingStaging);
                            db.SubmitChanges();
                        }
                        catch (Exception e)
                        {
                            comment += "[Exception caught when removing existing staging folders: " + e.Message + "]";
                        }
                        comment += ("[No Staging Folders Submitted]");
                    }
                }
                catch (Exception e)
                {
                    return new PagedData("Error: " + e.Message + e.Source + e.StackTrace + e.TargetSite + e.InnerException + e.HelpLink);
                }

            }
        return new PagedData("success! "+comment);
        }
        public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db)
        {

            string user_name = context.Request.Params.Get("user_name");
            if (isNull(user_name))
            {
                return new PagedData("CreateNewProject.ashx expects a user_name");
            }

            ProjectInformation newProject = new ProjectInformation();
            newProject.locked = true;           //start the project off as locked by the user who created it
            newProject.user_name = user_name;   //
            db.ProjectInformations.InsertOnSubmit(newProject);
            db.SubmitChanges();  //create the new project so we can have a new project_id with which to create new records in other tables


            //create a new record in dependent tables
            MISNew newMISNew = new MISNew();
            newMISNew.project_id = newProject.project_id;
            db.MISNews.InsertOnSubmit(newMISNew);
            db.SubmitChanges();

            MISNewDelivery newMISDelivery = new MISNewDelivery();
            newMISDelivery.mis_new_id = newMISNew.mis_new_id;
            db.MISNewDeliveries.InsertOnSubmit(newMISDelivery);

            MISUpdate newMISUpdate = new MISUpdate();
            newMISUpdate.project_id = newProject.project_id;
            newMISUpdate.description = "";
            db.MISUpdates.InsertOnSubmit(newMISUpdate);
            db.SubmitChanges();

            MISUpdateDeliveryChange newMISUpdateDeliveryChange = new MISUpdateDeliveryChange();
            newMISUpdateDeliveryChange.mis_update_id = newMISUpdate.mis_update_id;
            db.MISUpdateDeliveryChanges.InsertOnSubmit(newMISUpdateDeliveryChange);

            ProdInstallationBuffet prodBuffet = new ProdInstallationBuffet();
            prodBuffet.project_id = newProject.project_id;
            db.ProdInstallationBuffets.InsertOnSubmit(prodBuffet);

            PromptWorksheet promptWorksheet = new PromptWorksheet();
            promptWorksheet.project_id = newProject.project_id;
            promptWorksheet.prompt_worksheet = "";
            promptWorksheet.prompt_summary = "";
            db.PromptWorksheets.InsertOnSubmit(promptWorksheet);

            SWDSchedule swdSchedule = new SWDSchedule();
            swdSchedule.project_id = newProject.project_id;
            db.SWDSchedules.InsertOnSubmit(swdSchedule);

            TrafficRequirement trafficRequirement = new TrafficRequirement();
            trafficRequirement.project_id = newProject.project_id;
            db.TrafficRequirements.InsertOnSubmit(trafficRequirement);

            UatProdInstall uatProdInstall = new UatProdInstall();
            uatProdInstall.project_id = newProject.project_id;
            db.UatProdInstalls.InsertOnSubmit(uatProdInstall);

            db.SubmitChanges();

            //insert a history note that the project was created
            ProjectHistory historyNote = new ProjectHistory();
            historyNote.project_id = newProject.project_id;
            historyNote.user_name = user_name;
            historyNote.description = "Project created";
            historyNote.date = DateTime.Today.ToString("yyyy-MM-dd");
            db.ProjectHistories.InsertOnSubmit(historyNote);

            db.SubmitChanges();

            return new PagedData(new { newProject.project_id });
        }