Exemplo n.º 1
0
        public ActionResult AddStudent3()
        {
            ///Part 3 of the ADD STUDENT ACTION
            ///It is the final step of adding student
            ///The data will be retirve from the temp data stored in ADD_STUDENT_2 action
            try
            {
                AddStudent2ViewModel data = (AddStudent2ViewModel)TempData["reToAddStudent3"]; //get temp data and cast it into the model data
                //assemble the data into new view model
                AddStudent3ViewModel asvm = new AddStudent3ViewModel()
                {
                    AddmissionNumber = data.AddmissionNumber,
                    Name             = data.Name,
                    BForm            = data.BForm,
                    DOB        = data.DOB,
                    Gender     = data.Gender,
                    MonthlyFee = data.MonthlyFee,
                    Prevnst    = data.Prevnst,
                    ParentId   = data.ParentId,
                    Class      = data.Class
                };

                return(View(asvm)); //return the view model to the view
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
Exemplo n.º 2
0
 public ActionResult EditStudent(int id)
 {
     ///Action to Edit the details of respective student
     ///id is the Student Id of whcih the data has to be edited
     try
     {
         HttpCookie conString = Request.Cookies.Get("rwxgqlb");                         //getting the encrypted connection string from cookie
         Student    s         = new Student(id, Cryptography.Decrypt(conString.Value)); //initialize a new object of Student to get the values
         //copying the student's data into view model
         AddStudent2ViewModel asvm = new AddStudent2ViewModel
         {
             AddmissionNumber = s.AdmissionNumber,
             BForm            = s.BFormNumber,
             DOB        = s.DateOfBirth,
             Gender     = s.Gender,
             MonthlyFee = s.MonthlyFee,
             Name       = s.Name,
             Prevnst    = s.PreviousInstitute
         };
         ViewBag.StudentId = s.StudentId; //send the student Id to the view, by using the view bag, in order to use it into edit form
         return(View(asvm));              //return the view with the view model containing the values
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }
Exemplo n.º 3
0
 public ActionResult EditStudent(AddStudent2ViewModel model, int sId)
 {
     ///Post Method to get the values submitted from the form
     ///model contains the data of student
     ///sId is the Student Id to recognoize the student and update values
     try
     {
         ViewBag.StudentId = sId;                                                        //send student Id to the view by using the view bag
         HttpCookie conString = Request.Cookies.Get("rwxgqlb");                          //getting the encrypted connection string from the cookie
         Student    s         = new Student(sId, Cryptography.Decrypt(conString.Value)); //initialzed a new object of Student by the student Id to get the data and update it
         try
         {
             //setting the properties of Student obeject with the model values
             s.AdmissionNumber   = model.AddmissionNumber;
             s.BFormNumber       = model.BForm;
             s.DateOfBirth       = model.DOB;
             s.Gender            = model.Gender;
             s.MonthlyFee        = model.MonthlyFee;
             s.Name              = model.Name;
             s.PreviousInstitute = model.Prevnst;
         }
         catch (Exception ex)
         {
             ModelState.AddModelError(string.Empty, ex.Message);
             return(View());
         }
         //copying new values to the Student Details View Model
         StudentDetailsViewModel sdvm = new StudentDetailsViewModel
         {
             AdmissionNumber = s.AdmissionNumber,
             Name            = s.Name,
             Age             = s.Age.ToString(),
             BForm           = s.BFormNumber,
             Class           = s.Section.Class.Name,
             Section         = s.Section.Name,
             DOA             = s.DateOfAdmission.ToLongDateString(),
             Fee             = decimal.Round(s.MonthlyFee).ToString(),
             FName           = s.Parent.FatherName,
             Gender          = s.Gender + "",
             Id         = s.StudentId,
             PrevInst   = s.PreviousInstitute,
             RollNumber = s.RollNumber.ToString()
         };
         ViewBag.Success = true;                   //set the flag for the successful operation
         return(View("ViewStudentDetails", sdvm)); //return STUDENT_DETAILS VIEW with the view model containing the updated values
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }
Exemplo n.º 4
0
 public ActionResult AddStudent2(AddStudent2ViewModel model, int pId)
 {
     ///Post Method to get the submitted values from the view
     ///pId is the Parent Id to which the student will be added
     try
     {
         ViewBag.ParentId = pId; //send the parent Id to the view by using view bag
         if (!ModelState.IsValid)
         {
             return(View());
         }
         model.ParentId = pId;                    //assigning the pId to the Parent Id in the model
         TempData["reToAddStudent3"] = model;     //store the model data to the TempData to used it in other action
         return(RedirectToAction("AddStudent3")); //redirect the action to the 3rd part of Add student
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }