public void PreformLogin() { //Check Id/Password and decide if can login or not //Loads User (with exam list) and passes to WelcomePage User user = new User(); string enteredId = _view.Id; string enteredPass = _view.Password; using (var unit = new UnitOfWork(new DAL.ExamContext())) { user = unit.Users.GetById(enteredId); if (user != null) { if (enteredPass == user.Password) { user.Classrooms.ToList <Classroom>(); foreach (var classroom in user.Classrooms) { //user.Exams.AddRange(unit.Exams.Find(ex => ex.ClassroomId == classroom.Id).ToList()); var examList = unit.Exams.Find(ex => ex.ClassroomId == classroom.Id).ToList(); foreach (var exam in examList) { user.Exams.Add(exam); } if (user.Role == Users.Teacher) { classroom.Users.ToList(); } } } else { _view.CouldNotLogin("Incorect Password"); return; } } else { _view.CouldNotLogin("User Not Found"); return; } unit.Complete(); } if (user.Role == Users.Teacher) { foreach (var classroom in user.Classrooms) { classroom.Users.Remove(user); } } else if (user.Role == Users.Student) { user.UpdateExamsStatus(); } Login.Invoke(user, null); }
public async Task<ApiResult> CreateUser([FromBody]UserChangeDto userDto) { if (!ModelState.IsValid) { return new ApiResult(ModelState); } var user = new User(); await _userService.CreateUser(Mapper.Map(userDto, user)); return new ApiResult { Data = Mapper.Map(user, new UserDetailResultDto()) }; }
private void BtnAdd_Click(object sender, EventArgs e) { if (!FormValidation()) { return; } ; Library.Models.User user = new Library.Models.User(); user.FirstName = TxtFirstName.Text; user.LastName = TxtLastName.Text; user.UserName = TxtUserName.Text; user.Password = TxtPassword.Text; #region VERIFYING THAT DUPLICATE USER NAME IS NOT ENTERED TO THE SYSTEM List <Library.Models.User> us = _context.Users.Where(u => u.UserName.Contains(user.UserName)).ToList(); foreach (var item in us) { if (item.UserName == user.UserName) { LblUserName.ForeColor = Color.Red; MessageBox.Show("User name is already in use, please choose a different user name.", "Attention!"); return; } } #endregion _context.Users.Add(user); _context.SaveChanges(); FillUserDetails(); FormReset(); MessageBox.Show("New User is successfully added to the list.", "UPDATE"); }
private void DgvUser_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { BtnAdd.Visible = false; BtnUpdate.Visible = true; BtnDelete.Visible = true; FormReset(); foreach (var item in _context.Users.ToList()) { int Id = Convert.ToInt32(DgvUser.Rows[e.RowIndex].Cells[0].Value.ToString()); this.SelectedUser = _context.Users.Find(Id); TxtFirstName.Text = SelectedUser.FirstName; TxtLastName.Text = SelectedUser.LastName; TxtUserName.Text = SelectedUser.UserName; TxtPassword.Text = SelectedUser.Password; } }
public async Task Update(User user) { await _libraryContext.SaveChangesAsync(); }
public async Task<int> CreateUser(User b) { _libraryContext.LibraryUsers.Add(b); return await _libraryContext.SaveChangesAsync(); }