public ActionResult Register(RegisterModel data)
        {
            if (ModelState.IsValid)
            {
                UsersBL ubl = new UsersBL();
                if ((ubl.DoesUserNameExist(data.Username)) == true)
                {
                    ViewBag.Message += "\n Username already exists";
                    return(View());
                }
                if ((ubl.DoesEmailExist(data.Email)) == true)
                {
                    ViewBag.Message += "\n E-mail address already exists";
                    return(View());
                }
                else
                {
                    ViewBag.Message = "";
                    ubl.AddUser(data.Role, data.Username, data.Password, data.Name, data.Surname, data.Email, data.Residence,
                                data.Street, data.Town, data.Country);

                    return(RedirectToAction("Login", "Login"));
                }
            }
            return(View());
        }
Beispiel #2
0
        public ActionResult Save(User userModel)
        {
            if (userModel != null)
            {
                if (!users.GetUser().Any(c => c.ID == userModel.ID))
                {
                    // add
                    users.AddUser(userModel);
                }
                else
                {
                    // update
                    var currentUser = users.GetUser().FirstOrDefault(u => u.ID == userModel.ID);
                    if (currentUser != null)
                    {
                        var user = userModel;
                        currentUser.FName       = user.FName;
                        currentUser.LName       = user.LName;
                        currentUser.DateOfBirth = user.DateOfBirth;
                        currentUser.Rewards     = user.Rewards;
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
 public IHttpActionResult Post([FromBody] Users1 user)
 {
     try
     {
         UsersBL.AddUser(user);
         return(Ok());
     }
     catch
     {
         return(Conflict());
     }
 }
Beispiel #4
0
        public HttpResponseMessage AddUser([FromBody] Users model)
        {
            var authHeader = this.Request.Headers.GetValues("Authorization").FirstOrDefault();
            var token      = authHeader.Substring("Bearer ".Length);
            var handler    = new JwtSecurityTokenHandler();
            var jsonToken  = handler.ReadToken(token);
            var tokenS     = handler.ReadToken(token) as JwtSecurityToken;

            var UserName = tokenS.Claims.First(claim => claim.Type == "UserName").Value;

            model.Password = "******";

            var r = UBL.AddUser(model, UserName);

            if (!r)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            else
            {
                string body = string.Empty;
                using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Views/EmailTemplates/NewUser.html")))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{FullName}", model.FullName);
                body = body.Replace("{UserName}", model.UserName);
                body = body.Replace("{Password}", model.Password);

                Emails Email = new Emails()
                {
                    FromEmail    = ConfigurationManager.AppSettings["AdminEmail"].ToString(),
                    ToEmail      = model.Email,
                    SubjectEmail = "Oasis Alajuela - Registro satisfactorio",
                    BodyEmail    = body
                };

                MailMessage mm = new MailMessage(Email.FromEmail, Email.ToEmail)
                {
                    Subject      = Email.SubjectEmail,
                    Body         = Email.BodyEmail,
                    IsBodyHtml   = true,
                    BodyEncoding = Encoding.GetEncoding("utf-8")
                };

                SmtpClient smtp = new SmtpClient();
                smtp.Send(mm);

                return(this.Request.CreateResponse(HttpStatusCode.OK, r));
            }
        }
Beispiel #5
0
        public IHttpActionResult Register([FromBody] Users model)
        {
            model.RoleID = 1; /*New User*/
            var r = UBL.AddUser(model, model.FullName);

            if (!r)
            {
                return(StatusCode(HttpStatusCode.BadRequest));
            }
            else
            {
                string body = string.Empty;
                using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/Views/EmailTemplates/NewUser.html")))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{FullName}", model.FullName);
                body = body.Replace("{UserName}", model.UserName);
                body = body.Replace("{Password}", model.Password);

                Emails Email = new Emails()
                {
                    FromEmail    = ConfigurationManager.AppSettings["AdminEmail"].ToString(),
                    ToEmail      = model.Email,
                    SubjectEmail = "Oasis Alajuela - Registro satisfactorio",
                    BodyEmail    = body
                };

                MailMessage mm = new MailMessage(Email.FromEmail, Email.ToEmail)
                {
                    Subject      = Email.SubjectEmail,
                    Body         = Email.BodyEmail,
                    IsBodyHtml   = true,
                    BodyEncoding = Encoding.GetEncoding("utf-8")
                };

                SmtpClient smtp = new SmtpClient();
                smtp.Send(mm);
                Users NewUser = UBL.List().Where(x => x.UserName == model.UserName).FirstOrDefault();
                return(Ok(NewUser));
            }
        }
Beispiel #6
0
        private void AddNewUser(object sender, EventArgs e)
        {
            User user;

            UserForm uf = new UserForm();

            if (uf.ShowDialog() == DialogResult.OK)
            {
                user = new User
                {
                    FName       = uf.User.FName,
                    LName       = uf.User.LName,
                    DateOfBirth = uf.User.DateOfBirth,
                    Rewards     = uf.User.Rewards
                };

                Users.AddUser(user);

                DisplayUsers();
            }
        }
        public ActionResult Save(User user, string[] names)
        {
            if (user != null)
            {
                if (
                    string.IsNullOrEmpty(user.FName) ||
                    string.IsNullOrEmpty(user.LName) ||
                    (user.DateOfBirth.Year > DateTime.Now.Year ||
                     user.DateOfBirth.Year < DateTime.Now.Year - 150))
                {
                    return(new HttpStatusCodeResult(404, "Incorrect user data :("));
                }

                user.Rewards = new List <Reward>();

                if (names != null)
                {
                    foreach (string name in names)
                    {
                        if (rewards.GetRewards().Any(c => c.Title == name))
                        {
                            user.Rewards.Add(rewards.GetRewards().First(c => c.Title == name));
                        }
                    }
                }

                if (!users.GetUser().Any(c => c.ID == user.ID))
                {
                    users.AddUser(user);
                }
                else
                {
                    users.UpdateUser(user);
                }
            }

            return(RedirectToAction("Index"));
        }
        public void AddUser(SPAProjectManager.Entities.Users user)
        {
            var userBL = new UsersBL(mockContext);

            userBL.AddUser(user);
        }