public async Task <ResponseResult <StudentViewModel> > AddStudent(StudentViewModel data, SchoolProfile school) { using (var trans = _context.Database.BeginTransaction()) { var r = Shared.String.GenerateRandom(_settings.StudentIdLength, false, true, false, false); var studentId = $"{school.Code}{r}"; //check if studentID already exist while (_manager.GetList(o => o.StudentId == studentId).Count() > 0) { r = Shared.String.GenerateRandom(_settings.StudentIdLength, false, true, false, false); studentId = $"{school.Code}{r}"; } var username = $"{studentId}@{school.Name.Replace(" ", "_")}.com"; var user = new SchoolUser { UserName = username, Email = username, EmailConfirmed = true, //extended properties FirstName = data.FirstName, LastName = data.LastName, School = school, Type = UserType.Student, InsertedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now }; var password = $"{data.LastName.ToProperCase()}{r}!"; var result = await _userManager.CreateAsync(user, password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Student"); var student = await _manager.AddAsync(new Model.StudentProfile() { FirstName = data.FirstName, LastName = data.LastName, MiddleName = data.MiddleName, Gender = data.Gender, DOB = data.DOB, Email = data.Email, Phone = data.Phone, Mobile = data.Mobile, StudentId = studentId, School = school, User = user }); data.Id = student.Id; await trans.CommitAsync(); } } return(ResponseResult <StudentViewModel> .SetSuccess(data)); }
public async Task <ResponseResult <SchoolLevelViewModel> > UpdateSchoolLevel(SchoolLevelViewModel data) { using (var trans = _context.Database.BeginTransaction()) { var level = _manager.GetSingle(o => o.Id == data.Id); level.Name = data.Name; await _manager.UpdateAsync(level); await trans.CommitAsync(); } return(ResponseResult <SchoolLevelViewModel> .SetSuccess(data)); }
public async Task <ResponseResult <SchoolYearViewModel> > UpdateSchoolYear(SchoolYearViewModel data, SchoolProfile school) { await _manager.UpdateAsync(new Model.SchoolYear() { Id = data.Id, Name = data.Name, Start = data.Start.Value, End = data.End.Value, UpdatedDateTime = DateTime.Now }); return(ResponseResult <SchoolYearViewModel> .SetSuccess(data)); }
public async Task <ResponseResult <SchoolTeacherViewModel> > AddTeacher(SchoolTeacherViewModel data, SchoolProfile school) { using (var trans = _context.Database.BeginTransaction()) { var r = Shared.String.GenerateRandom(4, false, true, false, false); var username = $"{data.FirstName[0]}{data.LastName.ToLower()}_{r}@{school.Name.Replace(" ", "_")}.com"; //check if studentID already exist while (_manager.GetList(o => o.User.UserName == username, o => o.User).Count() > 0) { r = Shared.String.GenerateRandom(4, false, true, false, false); username = $"{data.FirstName[0]}{data.LastName.ToLower()}_{r}@{school.Name.Replace(" ", "_")}.com"; } var user = new SchoolUser { UserName = username, Email = username, EmailConfirmed = true, //extended properties FirstName = data.FirstName, LastName = data.LastName, School = school, Type = UserType.Teacher, InsertedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now, }; var password = $"{data.LastName.ToProperCase()}{r}!"; var result = await _userManager.CreateAsync(user, password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Teacher"); var teacher = await _manager.AddAsync(new SchoolTeacher() { FirstName = data.FirstName, MiddleName = data.MiddleName, LastName = data.LastName, Position = data.Position, User = user }); data.Id = teacher.Id; await trans.CommitAsync(); } } return(ResponseResult <SchoolTeacherViewModel> .SetSuccess(data)); }
public async Task <ResponseResult <SchoolYearViewModel> > AddSchoolYear(SchoolYearViewModel data, SchoolProfile school) { await _manager.AddAsync(new Model.SchoolYear() { Name = data.Name, Start = data.Start.Value, End = data.End.Value, InsertedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now, School = school }); return(ResponseResult <SchoolYearViewModel> .SetSuccess(data)); }
public async Task <ResponseResult <SchoolTeacherViewModel> > UpdateTeacher(SchoolTeacherViewModel data, SchoolProfile school) { using (var trans = _context.Database.BeginTransaction()) { var teacher = _manager.GetSingle(o => o.Id == data.Id); teacher.LastName = data.LastName; teacher.FirstName = data.FirstName; teacher.MiddleName = data.MiddleName; teacher.Position = data.Position; await _manager.UpdateAsync(teacher); await trans.CommitAsync(); } return(ResponseResult <SchoolTeacherViewModel> .SetSuccess(data)); }
public async Task <ResponseResult <SchoolLevelViewModel> > AddSchoolLevel(SchoolLevelViewModel data) { using (var trans = _context.Database.BeginTransaction()) { var school = _schoolManager.GetSingle(o => o.Id == data.SchoolId); var level = await _manager.AddAsync(new SchoolLevel() { Name = data.Name, School = school }); data.Id = level.Id; await trans.CommitAsync(); } return(ResponseResult <SchoolLevelViewModel> .SetSuccess(data)); }
public ResponseResult <SchoolUser> Users(string Id) { return(ResponseResult <SchoolUser> .SetSuccess(_user.GetUser(Id))); }
public ResponseResult <IEnumerable <SchoolUser> > Users() { return(ResponseResult <IEnumerable <SchoolUser> > .SetSuccess(_user.GetUsers())); }
public async Task <ResponseResult <StudentViewModel> > UpdateStudent(StudentViewModel data, SchoolProfile school) { using (var trans = _context.Database.BeginTransaction()) { if (data.CurrentAddress.Id == Guid.Empty) { data.CurrentAddress = await _addressManager.AddAsync(new StudentAddress() { Address = data.CurrentAddress.Address, City = data.CurrentAddress.City, Zip = data.CurrentAddress.Zip, Country = data.CurrentAddress.Country }); } else { data.CurrentAddress = await _addressManager.UpdateAsync(new StudentAddress() { Id = data.CurrentAddress.Id, Address = data.CurrentAddress.Address, City = data.CurrentAddress.City, Zip = data.CurrentAddress.Zip, Country = data.CurrentAddress.Country }); } if (data.PermanentAddress.Id == Guid.Empty) { data.PermanentAddress = await _addressManager.AddAsync(new StudentAddress() { Address = data.PermanentAddress.Address, City = data.PermanentAddress.City, Zip = data.PermanentAddress.Zip, Country = data.PermanentAddress.Country }); } else { data.PermanentAddress = await _addressManager.UpdateAsync(new StudentAddress() { Id = data.PermanentAddress.Id, Address = data.PermanentAddress.Address, City = data.PermanentAddress.City, Zip = data.PermanentAddress.Zip, Country = data.PermanentAddress.Country }); } await _manager.UpdateAsync(new StudentProfile() { Id = data.Id, StudentId = data.StudentId, FirstName = data.FirstName, LastName = data.LastName, MiddleName = data.MiddleName, DOB = data.DOB, Email = data.Email, Gender = data.Gender, Mobile = data.Mobile, Phone = data.Phone, CurrentAddress = data.CurrentAddress, PermanentAddress = data.PermanentAddress }); await trans.CommitAsync(); } return(ResponseResult <StudentViewModel> .SetSuccess(data)); }