Exemplo n.º 1
0
        public ActionResult Edit([Bind(Exclude = "ConfirmPassword")] DroneMainAdmin.Models.User user, int id)
        {
            DroneDBEntities drop = new DroneDBEntities();

            if (User.Identity.IsAuthenticated)
            {
                string username = User.Identity.Name;
                var    v        = drop.Users.Where(a => a.UserID == id).FirstOrDefault();
                try
                {
                    var adminchk = drop.Users.Where(a => a.EmailID == username).FirstOrDefault();
                    if (v != null && adminchk.AdminType == true)
                    {
                        string selected = (from sub in drop.Users
                                           where sub.UserID == id
                                           select sub.CountryName).FirstOrDefault();
                        ViewBag.SelectValue = new SelectList(drop.countries, "name", "name", selected);
                        string stateselect = (from sub in drop.Users
                                              where sub.UserID == id
                                              select sub.Provinance).FirstOrDefault();
                        ViewBag.StateSelect = new SelectList(drop.states, "name", "name", stateselect);
                        ViewBag.DateSet     = (from sub in drop.Users
                                               where sub.UserID == id
                                               select sub.DateOfBirth).FirstOrDefault();
                        user = dbe.Users.Find(id);
                    }
                    else
                    {
                        ViewBag.Message = "You are Not Authorize for View This Page";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "You are Not Authorize for View This Page";
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewBag.Message = "You are Not Authorize for View This Page";
                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Exemplo n.º 2
0
        public ActionResult ChangePass(DroneMainAdmin.Models.User user, string emailID, string activationcode, string oldpass, string id)
        {
            bool   status  = false;
            string message = "";

            using (DroneDBEntities dc = new DroneDBEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false;// Avoid Confirmation password does not match on save changes
                try
                {
                    var v = dc.Users.Where(a => a.GlobalID == new Guid(id)).FirstOrDefault();
                    if (v != null)
                    {
                        var changePass = user.Password;
                        changePass = Crypto.Hash(user.Password);
                        v.GlobalID = Guid.NewGuid();
                        v.Password = changePass;
                        dc.SaveChanges();
                        status  = true;
                        message = "Your Account Password is changed and your password has been sent to your registered Email address.Please Check your email id for updated new password .";
                        SendChangePassword(v.EmailID, "", user.Password.ToString());
                    }
                    else
                    {
                        message = "Invalid Request";
                        status  = false;
                    }
                }
                catch (Exception)
                {
                    message = "Invalid Request";
                    status  = false;
                }
            }
            ViewBag.Message = message;
            ViewBag.Status  = status;
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode,AdminType")] DroneMainAdmin.Models.User user)
        {
            bool   Status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                #region //Email is already Exist Check
                var isExist = IsEmailExist(user.EmailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email is already Exist");
                    return(View(user));
                }
                // user.UserID = user.UserID;
                #endregion
                #region Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion
                #region Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                DroneDBEntities drop   = new DroneDBEntities();
                int             county = Convert.ToInt16(user.CountryName);
                int             stat   = Convert.ToInt16(user.Provinance);
                //int county= Convert.ToInt16(user.CountryName);
                var nam = drop.countries.Where(p => p.id == county).FirstOrDefault();
                var sat = drop.states.Where(x => x.state_id == stat).FirstOrDefault();
                user.CountryName     = nam.name;
                user.Provinance      = sat.name;
                user.IsEmailVerified = false;
                if (user.SubEmail)
                {
                    user.SubEmail = true;
                }
                else
                {
                    user.SubEmail = false;
                }
                if (user.TermsAccepted)
                {
                    user.TermsAccepted = true;
                }
                else
                {
                    user.TermsAccepted = false;
                }
                user.Provinance  = user.Provinance;
                user.CountryName = user.CountryName;
                #endregion
                #region Save Data to Database
                using (DroneDBEntities dc = new DroneDBEntities())
                {
                    dc.Users.Add(user);
                    try
                    {
                        dc.SaveChanges();
                        SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString());
                        message = "Registration is successfully done. Account activation link " +
                                  " has been sent to your email id : " + user.EmailID;
                        Status = true;
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var eve in ex.EntityValidationErrors)
                        {
                            sb.AppendLine(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                        eve.Entry.Entity.GetType().Name,
                                                        eve.Entry.State));
                            foreach (var ve in eve.ValidationErrors)
                            {
                                sb.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                            ve.PropertyName,
                                                            ve.ErrorMessage));
                            }
                        }
                        message = "Error Message  :" + ex;
                    }
                    //Send Email to Users
                    return(RedirectToAction("Registration", "User"));
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Exemplo n.º 4
0
        public ActionResult Edit([Bind(Exclude = "ConfirmPassword")] DroneMainAdmin.Models.User user)
        {
            bool   status  = false;
            string message = "";

            if (User.Identity.IsAuthenticated)
            {
                if (!ModelState.IsValid)
                {
                    using (DroneDBEntities db = new DroneDBEntities())
                    {
                        string username = User.Identity.Name;
                        var    v        = dbe.Users.Where(a => a.UserID == user.UserID).FirstOrDefault();
                        try
                        {
                            var adminchk = dbe.Users.Where(a => a.EmailID == username).FirstOrDefault();
                            if (v != null && adminchk.AdminType == true)
                            {
                                db.Configuration.ValidateOnSaveEnabled = false; // Avoid Confirmation password does not match on save changes
                                v.FirstName  = user.FirstName;
                                v.MiddleName = user.MiddleName;
                                v.LastName   = user.LastName;
                                v.EmailID    = user.EmailID;
                                v.ContactNo  = user.ContactNo;
                                v.TeamName   = user.TeamName;
                                if (user.Password.Length <= 42)
                                {
                                    v.Password = Crypto.Hash(user.Password);
                                }
                                // v.Password = user.Password;
                                //  v.ConfirmPassword = user.ConfirmPassword;
                                // v.DateOfBirth = user.DateOfBirth;
                                if (user.IsEmailVerified)
                                {
                                    v.IsEmailVerified = true;
                                }
                                else
                                {
                                    v.IsEmailVerified = false;
                                }
                                v.CountryName = user.CountryName;
                                if (user.SubEmail)
                                {
                                    v.SubEmail = true;
                                }
                                else
                                {
                                    v.SubEmail = false;
                                }
                                v.Decscript = user.Decscript;
                                if (user.AdminType == true)
                                {
                                    v.AdminType = true;
                                }
                                else
                                {
                                    v.AdminType = false;
                                }
                                try
                                {
                                    //  db.Users.Add(v);
                                    // db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                                    db.Entry(v).State = System.Data.Entity.EntityState.Modified;
                                    db.SaveChanges();
                                }
                                catch (DbEntityValidationException ex)
                                {
                                    StringBuilder sb = new StringBuilder();
                                    foreach (var eve in ex.EntityValidationErrors)
                                    {
                                        sb.AppendLine(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                                    eve.Entry.Entity.GetType().Name,
                                                                    eve.Entry.State));
                                        foreach (var ve in eve.ValidationErrors)
                                        {
                                            sb.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                                        ve.PropertyName,
                                                                        ve.ErrorMessage));
                                        }
                                    }
                                    message = "Error Message  :" + ex;
                                }
                                status          = true;
                                ViewBag.Message = "User Profile is Succesfully Updated";
                            }
                            else
                            {
                                ViewBag.Message = "You are not Authorize for doing changes in User Record,\n for more contact administrator";
                            }
                        }
                        catch (Exception ex) { }
                    }
                }
            }
            return(RedirectToAction("Index", "TeamList"));
        }