public ActionResult EditParent(int pId) { ///Action to edit parent details ///pId is the parent id of which details have to be edited try { HttpCookie conString = Request.Cookies.Get("rwxgqlb"); //getting connection string from the cookie Parent p = new Parent(pId, Cryptography.Decrypt(conString.Value)); //new instance of parent with the given parent id //copying the data to the view model AddParentViewModel apvm = new AddParentViewModel { Address = p.HomeAddress, ElgibilityThreshold = p.EligibiltyThreshold, EmergencyContact = p.EmergencyContact, FatherName = p.FatherName, FCNIC = p.FatherCNIC, FCompanyCode = p.FatherMobile.CompanyCode, FCountryCode = p.FatherMobile.CountryCode, FNumber = p.FatherMobile.Number, MCompanyCode = p.MotherMobile.CompanyCode, MCountryCode = p.MotherMobile.CountryCode, MNumber = p.MotherMobile.Number, MotherName = p.MotherName }; ViewBag.ParentId = p.ParentId; //sending parent Id ot the view through ViewBag return(View(apvm)); //return view with view model } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult ShowParentList(Guid?subjectid) { AddParentViewModel apvm = new AddParentViewModel(); apvm.SubjectId = subjectid.Value; apvm.People = db.People.ToList(); return(PartialView("_AddParent", apvm)); }
public ActionResult EditParent(AddParentViewModel model, int id) { try { ViewBag.ParentId = id; //Sends id to the View by using View Bag HttpCookie conString = Request.Cookies.Get("rwxgqlb"); //get connection string from the cookies Parent p = new Parent(id, Cryptography.Decrypt(conString.Value)); //initalizes new instance by using the parent Id try { //updating the values into the database p.EligibiltyThreshold = model.ElgibilityThreshold; p.EmergencyContact = model.EmergencyContact; p.FatherCNIC = model.FCNIC; p.FatherMobile = new Models.HelperModels.MobileNumber(model.FCountryCode, model.FCompanyCode, model.FNumber); p.FatherName = model.FatherName; p.HomeAddress = model.Address; p.MotherMobile = new Models.HelperModels.MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber); p.MotherName = model.MotherName; } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } //copying data to the view model to show details of newly added parent ViewParentDetailsViewModel vpvm = new ViewParentDetailsViewModel { Address = p.HomeAddress, ElgibilityThreshold = p.EligibiltyThreshold, EmergencyContact = p.EmergencyContact, FatherName = p.FatherName, FCNIC = p.FatherCNIC, FNumber = p.FatherMobile.GetLocalViewFormat(), MNumber = p.MotherMobile.GetLocalViewFormat(), MotherName = p.MotherName, ParentId = p.ParentId, StudentsList = new List <ParentStudent>() }; foreach (var item in p.GetAllStudents()) { vpvm.StudentsList.Add(new ParentStudent { Class = item.Section.Class.Name, Name = item.Name, StudentId = item.StudentId }); } ViewBag.Success = true; //setting success flag to true after successful operation return(View("ViewParentDetails", vpvm)); //returning view to show newly added parent details } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult AddParent(AddParentViewModel model) { ///Post Method to Add Parent called on submitting the form ///model contains the data entered by the user try { if (!ModelState.IsValid) { return(View()); } HttpCookie conString = Request.Cookies.Get("rwxgqlb"); //getting connection string from the cookie Parent p; try { p = new Parent(model.FatherName, model.MotherName, model.FCNIC, new Models.HelperModels.MobileNumber(model.FCountryCode, model.FCompanyCode, model.FNumber), new Models.HelperModels.MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), model.Address, model.EmergencyContact, Math.Abs(model.ElgibilityThreshold), Cryptography.Decrypt(conString.Value)); //adding new parent } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } //copying data to view model ViewParentDetailsViewModel vpvm = new ViewParentDetailsViewModel { Address = p.HomeAddress, ElgibilityThreshold = p.EligibiltyThreshold, EmergencyContact = p.EmergencyContact, FatherName = p.FatherName, FCNIC = p.FatherCNIC, FNumber = p.FatherMobile.GetLocalViewFormat(), MNumber = p.MotherMobile.GetLocalViewFormat(), MotherName = p.MotherName, ParentId = p.ParentId, StudentsList = new List <ParentStudent>() }; //getting student belong to the parent foreach (var item in p.GetAllStudents()) { vpvm.StudentsList.Add(new ParentStudent { Class = item.Section.Class.Name, Name = item.Name, StudentId = item.StudentId }); } ViewBag.Success = true; return(View("ViewParentDetails", vpvm)); //returning newly added parent details } catch (Exception ex) { return(Content(ex.Message)); } }
public AddParentDialog(AddParentViewModel viewModel) { InitializeComponent(); DataContext = viewModel; }