Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. namespace ABC.ViewModels
  2. {
  3. public class UserInfoViewModel
  4. {
  5. public MasterSchoolInfo School { get; set; }
  6. public MasterTeacherInfo Teacher{ get; set; }
  7. public MasterStudentInfo Student { get; set; }
  8. public MasterParentInfo Parent { get; set; }
  9. public MasterUserInfo User { get; set; }
  10. public MasterUserRole Role { get; set; }
  11.  
  12. }
  13. }
  14.  
  15. [HttpPost]
  16. public ContentResult CreateSchool(UserInfoViewModel _usrData)
  17. {
  18. var content = string.Empty;
  19. if ((!String.IsNullOrEmpty(HttpContext.Session.GetString("UserEmail"))) && (!String.IsNullOrEmpty(HttpContext.Session.GetString("UserRole"))))
  20. {
  21. int UserId = Convert.ToInt32(HttpContext.Session.GetString("UserId"));
  22. string UserEmail = Convert.ToString(HttpContext.Session.GetString("UserEmail"));
  23. string UserRole = Convert.ToString(HttpContext.Session.GetString("UserRole"));
  24. byte[] salt = encryption.generatePasswordSalt("school");
  25. string password = encryption.generateHashedPassword("school", salt);
  26. if (UserRole == "Super Administrator")
  27. {
  28. _usrData.School.CreatedBy = UserEmail;
  29. _usrData.School.CreatedOn = DateTime.Now;
  30. _usrData.School.ApprovalStatus = true;
  31. _usrData.School.Status = true;
  32. MasterUserInfo userInfo = new MasterUserInfo();
  33. userInfo.RoleId = 4;
  34. userInfo.EmailId = _usrData.School.PrimaryEmailId;
  35. userInfo.Salt = Convert.ToBase64String(salt).ToString();
  36. userInfo.Password = password;
  37. userInfo.CreatedBy = UserEmail;
  38. userInfo.CreatedOn = DateTime.Now;
  39. userInfo.ApprovalStatus = true;
  40. userInfo.Status = true;
  41. //string[] str = schoolInfo.PrimaryEmailId.Split('.');
  42. //userInfo.Username = str[0].ToString();
  43. userInfo.Username = _usrData.User.Username.ToString();
  44. MasterSchoolInfo masterSchool = _context.Set<MasterSchoolInfo>().LastOrDefault();
  45. if (masterSchool != null)
  46. {
  47. var lastschoolcode = masterSchool.OpinschoolCode;
  48. var val = lastschoolcode.Substring(4, lastschoolcode.Length - 4);
  49. int r = Convert.ToInt32(val) + 1;
  50. string newusercode = "IESC000" + r;
  51. userInfo.UserCode = newusercode;
  52. _usrData.School.OpinschoolCode = newusercode;
  53. }
  54. else
  55. {
  56. string newusercode = "IESC000" + 1;
  57. userInfo.UserCode = newusercode;
  58. _usrData.School.OpinschoolCode = newusercode;
  59. }
  60. if (ModelState.IsValid)
  61. {
  62.  
  63. _context.MasterUserInfo.Add(userInfo);
  64. _context.SaveChanges();
  65.  
  66. MasterUserInfo masterUser = _context.Set<MasterUserInfo>().Last();
  67. _usrData.School.UserId = masterUser.Id;
  68. _context.MasterSchoolInfo.Add(_usrData.School);
  69. _context.SaveChanges();
  70. TempData["Message"] = "School Added Successfully!";
  71. content = "Success";
  72. }
  73. else
  74. {
  75. content = "Error";
  76. }
  77. }
  78. else
  79. {
  80. content = "Error";
  81. }
  82. }
  83. else
  84. {
  85. content = "Error";
  86. }
  87. return Content(content);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement