I am still a beginner and MVC entity framework when adding a user I want to check if UserName and email already exists or not. if there is a message is displayed . the addition is done correctly in database my preblème basis just to do the test on the presence of username and email ; if gasket Service class that CONTAIN the method and my controller if quelq'un peuc help me please
public void Create(User item) { item.Password = Cryptography.HashPassword(item.Password); var list = _userRepository.Get().ToList(); var Result = list.Where(user => user.UserName == item.UserName);
if (Result != null) return; else { _userRepository.Create(item); } }
My controller
[HttpPost] public ActionResult Create(User user, HttpPostedFileBase avatarfile, IEnumerable<int> roles, bool? createResource) { if (avatarfile != null) { user.Avatar = Guid.NewGuid() + Path.GetExtension(avatarfile.FileName); var filePath = Constants.PhotoFolder + user.Avatar; avatarfile.SaveAs(Server.MapPath(filePath)); } else { user.Avatar = "default-avatar.png"; } var result = ValidationHelper.Validate<UserValidator, User>(user); if (!result.IsValid) { ViewBag.Result = Constants.Failure; ViewBag.Errors = ValidationHelper.GetError(result); return View(); } _userService.Create(user);