Ejemplo n.º 1
0
        public void Add(TestViewModel testModel)
        {
            var newUser = new User
            {
                Firstname = testModel.Name//PROBA
            };

            dataContext.Users.Add(newUser);
            dataContext.SaveChanges();
        }
Ejemplo n.º 2
0
 public void Edit(object userObject)
 {
     User oldUser = new User();
     User newUser = (User)userObject;
     oldUser = context.Users.Find(newUser.UserId);
     if (oldUser != null)
     {
         FillFields(oldUser, newUser);
         context.Entry(oldUser).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
        public ActionResult Contact(User user, Boolean registered)
        {
            if (ModelState.IsValid)
            {
                var body = "";
                var message = new MailMessage();
                message.To.Add(new MailAddress(user.Email));  // replace with valid value
                message.From = new MailAddress("*****@*****.**");  // replace with valid value

                if (registered)
                {
                    message.Subject = "Registration to Hinttech";
                    body = "<p>Your registration is <b>APPROVED</b>.</p>";
                }
                else
                {
                    message.Subject = "Unregistered from Hinttech";
                    body = "<p>Your registration isn't <b>APPROVED</b> anymore.</p>";
                }

                message.Body = string.Format(body);
                message.IsBodyHtml = true;

                using (var smtp = new SmtpClient())
                {
                    var credential = new NetworkCredential
                    {
                        UserName = "******",  // replace with valid value
                        Password = "******"  // replace with valid value
                    };

                    smtp.Credentials = credential;
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    //await smtp.mailSendAsync(msg);
                    smtp.Send(message);
                    return RedirectToAction("ShowAllUsers");
                }
            }
            return RedirectToAction("ShowAllUsers");
        }
        public ActionResult RegisterPage(RegisterViewModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                UsersService userService = new UsersService();
                User currentUser = userService.FindUserByUsername(model.Username);

                if (currentUser != null)
                {
                    ViewBag.Error = "Username already exist!";
                    return View();
                }
                if (!model.Password.Equals(model.repeatPassword))
                {
                    ViewBag.Error = "Password doesn't match!";
                    return View();
                }
                currentUser = userService.FindUserByEmail(model.Email);
                if (currentUser != null)
                {
                    ViewBag.Error = "Email address already exist!!";
                    return View();
                }

                User user = new User();
                user.Email = model.Email;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Password = model.Password;
                user.Username = model.Username;
                user.DateCreated = DateTime.Now;
                user.IsUserAdmin = false;
                user.IsUserRegistered = false;
                user.LastLoginDate = DateTime.Now;
                user.VacationDays = 20;

                if (file != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] array = ms.GetBuffer();
                        if (array.Length > 55000)
                        {
                            ViewBag.Error = "Image size can't be more than ~50Kb!!";
                            return View();
                        }
                        user.ProfilePicture = array;
                    }

                }
                userService.Create(user);
                return RedirectToAction("RegisterOK", "Home");
            }
            return View();
        }
Ejemplo n.º 5
0
 public void Add(User testModel)
 {
     dataContext.Users.Add(testModel);
     dataContext.SaveChanges();
 }
Ejemplo n.º 6
0
 private void FillFields(User oldUser, User newUSer)
 {
     oldUser.Email = newUSer.Email;
     oldUser.FirstName = newUSer.FirstName;
     oldUser.LastName = newUSer.LastName;
     oldUser.Password = newUSer.Password;
     oldUser.Username = newUSer.Username;
     oldUser.ProfilePicture = newUSer.ProfilePicture;
 }
Ejemplo n.º 7
0
 public object FindById(int userId)
 {
     User user = new User();
     user = context.Users.Find(userId);
     return user;
 }