コード例 #1
0
 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));
     }
 }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
 public ActionResult ViewParentDetails(int pId)
 {
     ///Action to View Details of a parent
     ///pTd is the parent Id of which details want to be view
     try
     {
         HttpCookie conString = Request.Cookies.Get("rwxgqlb");                         //getting connection string from the cookie
         Parent     p         = new Parent(pId, Cryptography.Decrypt(conString.Value)); //initializing new instance of parent by using parent Id
         //copying data to 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 students 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
             });
         }
         return(View(vpvm)); //return view by passing model
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }