コード例 #1
0
        public HttpResponseMessage UpdateUser([FromBody] User value, [FromUri] int userId)
        {
            if (ModelState.IsValid)
            {
                return((LogicUser.UpdateUser(value, userId)) ?
                       new HttpResponseMessage(HttpStatusCode.OK) :
                       new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter())
                });
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the user is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter())
            });
        }
コード例 #2
0
        private void SendEmail(User user)
        {
            string      email = user.UserEmail;
            List <User> users = LogicUser.GetAllUsers();

            try
            {
                string subject = "Email Subject";

                user.VerifyPassword = CreatePassword(6);;
                LogicUser.UpdateUser(user, user.UserId);
                string      FromMail   = "*****@*****.**";
                string      emailTo    = email;
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress(FromMail);
                mail.To.Add(emailTo);
                mail.Subject = subject;
                mail.Body    = user.VerifyPassword;
                SmtpServer.UseDefaultCredentials = true;
                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new NetworkCredential("*****@*****.**", "0533121776");
                SmtpServer.EnableSsl   = true;
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                var x = ex.Message;
            }
        }