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);