public HttpResult Register(User item) { if (item == null || string.IsNullOrEmpty(item.UserName) || string.IsNullOrEmpty(item.Password) || string.IsNullOrEmpty(item.Email)) { return(new HttpResult { RetCode = 1, Message = "User Name, Email or Password can't be empty!" }); } else if (repo.Exists(item.UserName)) { return(new HttpResult { RetCode = 1, Message = string.Format("User with name [{0}] is already existing, choose another name.", item.UserName) }); } else { var foo = new System.ComponentModel.DataAnnotations.EmailAddressAttribute(); if (!foo.IsValid(item.Email)) { return(new HttpResult { RetCode = 1, Message = "The Email address is not valid!" }); } else { repo.Add(item); return(new HttpResult { RetCode = 0, Message = "Registration succeed!" }); } } }