本文介绍了验证用户和电子邮件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在添加用户时,我仍然是初学者和MVC实体框架,我想检查UserName和电子邮件是否已经存在。如果有消息显示。在数据库我的preblème基础上正确完成添加只是为了对用户名和电子邮件的存在进行测试;如果垫圈服务类包含方法和我的控制器如果quelq'un peuc请帮助我



我的班级服务



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

my class service

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





感谢



Thanks

推荐答案

var Result = list.Where(user => user.UserName == item.UserName || user.Email== item.Email);


这篇关于验证用户和电子邮件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 01:58