public ActionResult Index() { Models.Educator educator = new Models.Educator(); Models.Child child = new Models.Child(); Models.GiveAchievement giveAchievement = new Models.GiveAchievement(); Models.Achievements achievement = new Models.Achievements(); Models.Achievements achievement1 = new Models.Achievements(); Models.Achievements[] achievements = new Models.Achievements[2] { achievement, achievement1 }; Random rand = new Random(); achievement1.AchieveType = Models.AchieveType.Educator; for (int i = 0; i < 10; i++) { int index = rand.Next(0, 2); giveAchievement.GiveAchievments(achievements[index], child); giveAchievement.GiveAchievments(achievements[index], educator); } ViewBag.EducatorStatus = educator.Status; ViewBag.EducatorAchieveCount = educator.Achievements.Count; ViewBag.ChildAchieveCount = child.Achievements.Count; return(View()); }
public ActionResult Add(AddChildViewModel model) { if (ModelState.IsValid) { var child = new Models.Child() { Name = model.Name, Born = model.Born == null ? DateTime.Now : DateTime.Parse(model.Born.ToString()), Gender = model.Gender, ParentId = this.User.Identity.GetUserId() }; this.Data.Children.Add(child); this.Data.SaveChanges(); return(RedirectToAction("Index")); } TempData["success"] = model.Name + " was successfully added"; return(View(model)); }
/// <summary> /// This method returns the Child object filled with information from /// the inputs in this control so that the content page can interact with it /// </summary> /// <returns>The filled Child object if validation succeeds, null otherwise</returns> public Models.Child GetChild() { if (ASPxEdit.AreEditorsValid(this, ValidationGroup)) { //Get the child pk int childPK = Convert.ToInt32(hfChildPK.Value); //To hold the child object Models.Child child; //Determine if the child already exists if (childPK > 0) { using (PyramidContext context = new PyramidContext()) { child = context.Child.AsNoTracking().Where(c => c.ChildPK == childPK).FirstOrDefault(); } } else { child = new Models.Child(); } //Set the values from the inputs child.FirstName = txtFirstName.Value.ToString(); child.LastName = txtLastName.Value.ToString(); child.BirthDate = Convert.ToDateTime(deDOB.Value); child.GenderCodeFK = Convert.ToInt32(ddGender.Value); child.EthnicityCodeFK = Convert.ToInt32(ddEthnicity.Value); child.RaceCodeFK = Convert.ToInt32(ddRace.Value); //Return the object return(child); } else { if (String.IsNullOrWhiteSpace(ValidationMessageToDisplay)) { ValidationMessageToDisplay = "Validation failed, see above for details!"; } return(null); } }
public void recursiveComments(Models.Child comment) { //if (comment.data.replies.data.children.Count != 0) comment.data.indent = new Thickness(20 + i * 20, 20, 20, 8); comment.data.indentText = new Thickness(20 + i * 20, 0, 20, 8); if (comment.data.replies != null) { i++; postPage.addComment(comment.data); foreach (Models.Child com in comment.data.replies.data.children) { com.data.indent = new Thickness(20 + i * 20, 20, 20, 8); com.data.indentText = new Thickness(20 + i * 20, 0, 20, 8); string data = com.data.body; com.data.body = "@" + comment.data.author + " " + data; recursiveComments(com); } i--; } else { postPage.addComment(comment.data); } }
/// <summary> /// This method executes when the user clicks the delete button for a child /// and it deletes the child information from the database /// </summary> /// <param name="sender">The lbDeleteChild LinkButton</param> /// <param name="e">The Click event</param> protected void lbDeleteChild_Click(object sender, EventArgs e) { if (currentProgramRole.AllowedToEdit.Value) { //Get the PK from the hidden field int?removeChildProgramPK = (String.IsNullOrWhiteSpace(hfDeleteChildProgramPK.Value) ? (int?)null : Convert.ToInt32(hfDeleteChildProgramPK.Value)); //Remove the role if the PK is not null if (removeChildProgramPK != null) { try { using (PyramidContext context = new PyramidContext()) { //Get the child program row to remove ChildProgram childProgramToRemove = context.ChildProgram .Find(removeChildProgramPK); //Get the child to remove Models.Child childToRemove = context.Child .Where(c => c.ChildPK == childProgramToRemove.ChildFK).FirstOrDefault(); //Get the notes to remove and remove them List <ChildNote> notesToRemove = context.ChildNote.Where(cn => cn.ChildFK == childProgramToRemove.ChildFK).ToList(); context.ChildNote.RemoveRange(notesToRemove); //Get the status rows to remove and remove them List <ChildStatus> statusToRemove = context.ChildStatus.Where(cs => cs.ChildFK == childProgramToRemove.ChildFK).ToList(); context.ChildStatus.RemoveRange(statusToRemove); //Get the classroom assignments to remove and remove them List <ChildClassroom> classroomAssignmentsToRemove = context.ChildClassroom.Where(cc => cc.ChildFK == childProgramToRemove.ChildFK).ToList(); context.ChildClassroom.RemoveRange(classroomAssignmentsToRemove); //Remove the child program row context.ChildProgram.Remove(childProgramToRemove); //Remove the child context.Child.Remove(childToRemove); //Save all the changes to the database context.SaveChanges(); //Show a success message msgSys.ShowMessageToUser("success", "Success", "Successfully deleted child!", 10000); } } catch (DbUpdateException dbUpdateEx) { //Check if it is a foreign key error if (dbUpdateEx.InnerException?.InnerException is SqlException) { //If it is a foreign key error, display a custom message SqlException sqlEx = (SqlException)dbUpdateEx.InnerException.InnerException; if (sqlEx.Number == 547) { msgSys.ShowMessageToUser("danger", "Error", "Could not delete the child, there are related records in the system!<br/><br/>If you do not know what related records exist, please contact tech support via ticket.", 120000); } else { msgSys.ShowMessageToUser("danger", "Error", "An error occurred while deleting the child!", 120000); } } else { msgSys.ShowMessageToUser("danger", "Error", "An error occurred while deleting the child!", 120000); } //Log the error Elmah.ErrorSignal.FromCurrentContext().Raise(dbUpdateEx); } //Rebind the child controls bsGRChildren.DataBind(); BindRaceChart(); } else { msgSys.ShowMessageToUser("danger", "Error", "Could not find the child to delete!", 120000); } } else { msgSys.ShowMessageToUser("danger", "Error", "You are not authorized to make changes!", 120000); } }
/// <summary> /// This method takes a primary key and it fills the inputs in the /// control with the information in the Child table for that primary key /// </summary> /// <param name="childProgramPK">The primary key of the ChildProgram record</param> /// <param name="programFK">The primary key for the program which this child will be in</param> /// <param name="readOnly">True if the user is only allowed to view the values</param> public void InitializeWithData(int childProgramPK, int programFK, bool readOnly) { using (PyramidContext context = new PyramidContext()) { //Fill the Gender drop-down var genders = context.CodeGender.AsNoTracking().OrderBy(cg => cg.OrderBy).ToList(); ddGender.DataSource = genders; ddGender.DataBind(); //Fill the Ethnicity drop-down var ethnicities = context.CodeEthnicity.AsNoTracking().OrderBy(ce => ce.OrderBy).ToList(); ddEthnicity.DataSource = ethnicities; ddEthnicity.DataBind(); //Fill the Race drop-down var races = context.CodeRace.AsNoTracking().OrderBy(cr => cr.OrderBy).ToList(); ddRace.DataSource = races; ddRace.DataBind(); //Fill the Discharge Reason drop-down var dischargeReasons = context.CodeDischargeReason.AsNoTracking().OrderBy(cdr => cdr.OrderBy).ToList(); ddDischargeReason.DataSource = dischargeReasons; ddDischargeReason.DataBind(); //Fill the used IDs hidden field var usedIDs = context.ChildProgram .AsNoTracking() .Where(cp => cp.ProgramFK == programFK && cp.ChildProgramPK != childProgramPK) .OrderBy(cp => cp.ProgramSpecificID) .Select(cp => cp.ProgramSpecificID) .ToList(); hfUsedIDs.Value = string.Join(",", usedIDs); //Set the program fk hidden field hfProgramFK.Value = programFK.ToString(); if (childProgramPK > 0) { //If this is an edit, fill the form with the child's information //Get the objects Models.ChildProgram childProgram = context.ChildProgram.AsNoTracking() .Include(cp => cp.Child) .Where(cp => cp.ChildProgramPK == childProgramPK) .FirstOrDefault(); Models.Child child = (childProgram == null ? new Models.Child() : childProgram.Child); //Fill the hidden fields hfChildPK.Value = child.ChildPK.ToString(); hfChildProgramPK.Value = childProgram.ChildProgramPK.ToString(); //Fill the input fields txtFirstName.Value = child.FirstName; txtLastName.Value = child.LastName; deDOB.Value = child.BirthDate.ToString("MM/dd/yyyy"); txtProgramID.Value = childProgram.ProgramSpecificID; deEnrollmentDate.Value = childProgram.EnrollmentDate.ToString("MM/dd/yyyy"); ddGender.SelectedItem = ddGender.Items.FindByValue(child.GenderCodeFK); ddEthnicity.SelectedItem = ddEthnicity.Items.FindByValue(child.EthnicityCodeFK); ddRace.SelectedItem = ddRace.Items.FindByValue(child.RaceCodeFK); ddDLL.SelectedItem = ddDLL.Items.FindByValue(childProgram.IsDLL); ddIEP.SelectedItem = ddIEP.Items.FindByValue(childProgram.HasIEP); deDischargeDate.Value = (childProgram.DischargeDate.HasValue ? childProgram.DischargeDate.Value.ToString("MM/dd/yyyy") : ""); ddDischargeReason.SelectedItem = ddDischargeReason.Items.FindByValue(childProgram.DischargeCodeFK); txtDischargeReasonSpecify.Value = childProgram.DischargeReasonSpecify; } //Set the controls usability txtFirstName.ReadOnly = readOnly; txtLastName.ReadOnly = readOnly; deDOB.ReadOnly = readOnly; txtProgramID.ReadOnly = readOnly; deEnrollmentDate.ReadOnly = readOnly; ddGender.ReadOnly = readOnly; ddEthnicity.ReadOnly = readOnly; ddRace.ReadOnly = readOnly; ddDLL.ReadOnly = readOnly; ddIEP.ReadOnly = readOnly; deDischargeDate.ReadOnly = readOnly; ddDischargeReason.ReadOnly = readOnly; txtDischargeReasonSpecify.ReadOnly = readOnly; } }