/// <summary> /// Displays the details of a /// </summary> /// <param name="id"></param> /// <param name="s"></param> /// <param name="err"></param> /// <returns></returns> public ActionResult ViewTeacherDetails(int id, bool s = false, bool err = false) { ViewBag.Success = s; ViewBag.Error = err; try { HttpCookie conString = Request.Cookies.Get("rwxgqlb"); Teacher t = new Teacher(id, Cryptography.Decrypt(conString.Value)); ViewTeacherDetailsViewModel vtdvm = new ViewTeacherDetailsViewModel { Address = t.Address, CNIC = t.CNIC, Gender = t.Gender + "", Id = t.StaffId, MNumber = t.PhoneNumber.GetLocalViewFormat(), Name = t.Name, Qualifications = new List <TeacherQualification>(), Salary = decimal.Round(t.Salary), Sections = new List <TeacherSection>(), JoiningDate = t.Joiningdate.ToLongDateString() }; foreach (var item in t.Qualifications) { vtdvm.Qualifications.Add(new TeacherQualification { Degree = item.Degree, Id = item.Id, Year = item.Year.ToString(), TeacherId = t.StaffId }); } foreach (var item in t.GetAssignedSections()) { vtdvm.Sections.Add(new TeacherSection { Class = item.Section.Class.Name, Section = item.Section.Name, SectionId = item.Section.SectionId, Subject = item.Subject.Name, SubjectId = item.Subject.SubjectId, TeacherId = t.StaffId }); } return(View(vtdvm)); } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult AddStaff(AddStaffViewModel model) { try { HttpCookie conString = Request.Cookies.Get("rwxgqlb"); //getting the connection string from cookies if (!ModelState.IsValid) { return(View()); } if (model.StaffType == StaffTypes.NonTeaching && model.JobType == null) { ModelState.AddModelError("JobType", "This field is required"); //adding model error which displayed on invalid entry return(View()); } NonTeachingStaff nts = null; Teacher t = null; try { if (model.StaffType == StaffTypes.NonTeaching) { nts = new NonTeachingStaff(model.Name, model.CNIC, model.Address, new Models.HelperModels.MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), model.Salary, model.Gender, model.JobType, Cryptography.Decrypt(conString.Value)); } else if (model.StaffType == StaffTypes.Teacher) { t = new Teacher(model.Name, model.CNIC, model.Address, new Models.HelperModels.MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), model.Salary, model.Gender, Cryptography.Decrypt(conString.Value)); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } if (model.StaffType == StaffTypes.Teacher && t != null) { ViewTeacherDetailsViewModel vtdvm = new ViewTeacherDetailsViewModel { Address = t.Address, CNIC = t.CNIC, Gender = t.Gender + "", Id = t.StaffId, MNumber = t.PhoneNumber.GetLocalViewFormat(), Name = t.Name, Qualifications = new List <TeacherQualification>(), Salary = decimal.Round(t.Salary), Sections = new List <TeacherSection>(), JoiningDate = t.Joiningdate.ToLongDateString() }; foreach (var item in t.Qualifications) { vtdvm.Qualifications.Add(new TeacherQualification { Degree = item.Degree, Id = item.Id, Year = item.Year.ToString(), TeacherId = t.StaffId }); } foreach (var item in t.GetAssignedSections()) { vtdvm.Sections.Add(new TeacherSection { Class = item.Section.Class.Name, Section = item.Section.Name, SectionId = item.Section.SectionId, Subject = item.Subject.Name, SubjectId = item.Subject.SubjectId, TeacherId = t.StaffId }); } ViewBag.Success = true; return(View("ViewTeacherDetails", vtdvm)); } else if (model.StaffType == StaffTypes.NonTeaching && nts != null) { ViewNonStaffDetailsViewModel vnvm = new ViewNonStaffDetailsViewModel { Address = nts.Address, CNIC = nts.CNIC, Gender = nts.Gender + "", Id = nts.StaffId, JobType = nts.JobType, MNumber = nts.PhoneNumber.GetLocalViewFormat(), Name = nts.Name, Salary = decimal.Round(nts.Salary), JoiningDate = nts.Joiningdate.ToLongDateString() }; ViewBag.Success = true; return(View("ViewNonStaffDetails", vnvm)); } else { return(View()); } } catch (Exception ex) { return(Content(ex.Message)); } }