Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ABC.ViewModels
- {
- public class UserInfoViewModel
- {
- public MasterSchoolInfo School { get; set; }
- public MasterTeacherInfo Teacher{ get; set; }
- public MasterStudentInfo Student { get; set; }
- public MasterParentInfo Parent { get; set; }
- public MasterUserInfo User { get; set; }
- public MasterUserRole Role { get; set; }
- }
- }
- [HttpPost]
- public ContentResult CreateSchool(UserInfoViewModel _usrData)
- {
- var content = string.Empty;
- if ((!String.IsNullOrEmpty(HttpContext.Session.GetString("UserEmail"))) && (!String.IsNullOrEmpty(HttpContext.Session.GetString("UserRole"))))
- {
- int UserId = Convert.ToInt32(HttpContext.Session.GetString("UserId"));
- string UserEmail = Convert.ToString(HttpContext.Session.GetString("UserEmail"));
- string UserRole = Convert.ToString(HttpContext.Session.GetString("UserRole"));
- byte[] salt = encryption.generatePasswordSalt("school");
- string password = encryption.generateHashedPassword("school", salt);
- if (UserRole == "Super Administrator")
- {
- _usrData.School.CreatedBy = UserEmail;
- _usrData.School.CreatedOn = DateTime.Now;
- _usrData.School.ApprovalStatus = true;
- _usrData.School.Status = true;
- MasterUserInfo userInfo = new MasterUserInfo();
- userInfo.RoleId = 4;
- userInfo.EmailId = _usrData.School.PrimaryEmailId;
- userInfo.Salt = Convert.ToBase64String(salt).ToString();
- userInfo.Password = password;
- userInfo.CreatedBy = UserEmail;
- userInfo.CreatedOn = DateTime.Now;
- userInfo.ApprovalStatus = true;
- userInfo.Status = true;
- //string[] str = schoolInfo.PrimaryEmailId.Split('.');
- //userInfo.Username = str[0].ToString();
- userInfo.Username = _usrData.User.Username.ToString();
- MasterSchoolInfo masterSchool = _context.Set<MasterSchoolInfo>().LastOrDefault();
- if (masterSchool != null)
- {
- var lastschoolcode = masterSchool.OpinschoolCode;
- var val = lastschoolcode.Substring(4, lastschoolcode.Length - 4);
- int r = Convert.ToInt32(val) + 1;
- string newusercode = "IESC000" + r;
- userInfo.UserCode = newusercode;
- _usrData.School.OpinschoolCode = newusercode;
- }
- else
- {
- string newusercode = "IESC000" + 1;
- userInfo.UserCode = newusercode;
- _usrData.School.OpinschoolCode = newusercode;
- }
- if (ModelState.IsValid)
- {
- _context.MasterUserInfo.Add(userInfo);
- _context.SaveChanges();
- MasterUserInfo masterUser = _context.Set<MasterUserInfo>().Last();
- _usrData.School.UserId = masterUser.Id;
- _context.MasterSchoolInfo.Add(_usrData.School);
- _context.SaveChanges();
- TempData["Message"] = "School Added Successfully!";
- content = "Success";
- }
- else
- {
- content = "Error";
- }
- }
- else
- {
- content = "Error";
- }
- }
- else
- {
- content = "Error";
- }
- return Content(content);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement