Example #1
0
        public ActionResult User_add(ETUser addUser)
        {
            TempData["messagealert"] = string.Empty;
            ViewBag.messagealert     = string.Empty;

            if (ModelState.IsValid)
            {
                if (addUser != null)
                {
                    if (repUsers.LogInNameIsExist(addUser.LoginName, 0))
                    {
                        ViewBag.messagealert  = "LogInName already exist";
                        ViewBag.UserTitles    = repUsers.getDataValues("Title", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.Gender        = repUsers.getDataValues("Gender", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.MaritalStatus = repUsers.getDataValues("MaritalStatus", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.UserLevel     = repUsers.getDataValues("UserLevel", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.ReportingUser = repUsers.getMappedReportingUser();
                        ViewBag.DeviceType    = repUsers.getDataValues("DeviceType", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.Role          = repUsers.getRole();
                        return(View(addUser));
                    }
                    else if (repUsers.EmailIsExist(addUser.Email, 0) || !Common.IsValidEmail(addUser.Email))
                    {
                        if (!Common.IsValidEmail(addUser.Email))
                        {
                            ViewBag.messagealert = "Please Enter Valid Email";
                        }
                        else
                        {
                            ViewBag.messagealert = "Email already exist";
                        }
                        ViewBag.UserTitles    = repUsers.getDataValues("Title", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.Gender        = repUsers.getDataValues("Gender", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.MaritalStatus = repUsers.getDataValues("MaritalStatus", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.UserLevel     = repUsers.getDataValues("UserLevel", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.ReportingUser = repUsers.getMappedReportingUser();
                        ViewBag.DeviceType    = repUsers.getDataValues("DeviceType", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.Role          = repUsers.getRole();
                        return(View(addUser));
                    }
                    else if (repUsers.PhoneIsExist(addUser.Phone, 0))
                    {
                        ViewBag.messagealert  = "Phone already exist";
                        ViewBag.UserTitles    = repUsers.getDataValues("Title", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.Gender        = repUsers.getDataValues("Gender", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.MaritalStatus = repUsers.getDataValues("MaritalStatus", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.UserLevel     = repUsers.getDataValues("UserLevel", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.ReportingUser = repUsers.getMappedReportingUser();
                        ViewBag.DeviceType    = repUsers.getDataValues("DeviceType", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                        ViewBag.Role          = repUsers.getRole();
                        return(View(addUser));
                    }
                    else
                    {
                        //try
                        //{
                        addUser.SourceOfCreation = "User Form";
                        addUser.Password         = Common.EncryptPassword(addUser.Password);
                        addUser.ConfirmPassword  = Common.EncryptPassword(addUser.ConfirmPassword);
                        addUser.UserID           = repUsers.UserIdGeneration();
                        addUser.CreatedBy        = Convert.ToInt64(Session["UserID"]);
                        addUser.CreatedDate      = DateTime.Now;
                        addUser.ModifiedBy       = Convert.ToInt64(Session["UserID"]);
                        addUser.ModifiedDate     = DateTime.Now;
                        dbEntities.ETUsers.Add(addUser);
                        dbEntities.SaveChanges();

                        ETUserVerified userVerified = new ETUserVerified();
                        userVerified.UserID           = addUser.UserID;
                        userVerified.IsEmailVefified  = false;
                        userVerified.IsPhoneVerified  = false;
                        userVerified.IsOtherVerified  = false;
                        userVerified.IsOtherVerified1 = false;
                        userVerified.IsOtherVerified2 = false;
                        userVerified.IsOtherVerified3 = false;
                        userVerified.IsActive         = true;
                        userVerified.CreatedBy        = Convert.ToInt64(Session["UserID"]);
                        userVerified.CreatedDate      = DateTime.Now;
                        userVerified.ModifiedBy       = Convert.ToInt64(Session["UserID"]);
                        userVerified.ModifiedDate     = DateTime.Now;
                        dbEntities.ETUserVerifieds.Add(userVerified);
                        dbEntities.SaveChanges();

                        if (addUser.UserID != 0)
                        {
                            TempData["messagealert"] = Status.Save;
                        }
                        //}
                        //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                        //{
                        //    Exception raise = dbEx;
                        //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                        //    {
                        //        foreach (var validationError in validationErrors.ValidationErrors)
                        //        {
                        //            string message = string.Format("{0}:{1}",
                        //                validationErrors.Entry.Entity.ToString(),
                        //                validationError.ErrorMessage);
                        //            // raise a new exception nesting
                        //            // the current instance as InnerException
                        //            raise = new InvalidOperationException(message, raise);
                        //        }
                        //    }
                        //    throw raise;
                        //}
                    }
                }
                return(RedirectToAction("Index", "User"));
            }
            return(View());
        }
        public ActionResult SignUp(SignUp updateUser)
        {
            TempData["messagealert"] = string.Empty;
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                UserVal = new ETUser();

                if (repUser.LogInNameIsExist(updateUser.LoginName, 0))
                {
                    ViewBag.messagealert  = "LogInName already exist";
                    ViewBag.UserTitles    = repUser.getDataValues("Title", "0", Convert.ToInt64(Session["UserID"]), 1);         // Need to change
                    ViewBag.Gender        = repUser.getDataValues("Gender", "0", Convert.ToInt64(Session["UserID"]), 1);        // Need to change
                    ViewBag.MaritalStatus = repUser.getDataValues("MaritalStatus", "0", Convert.ToInt64(Session["UserID"]), 1); // Need to change
                    ViewBag.DeviceType    = repUser.getDataValues("DeviceType", "0", Convert.ToInt64(Session["UserID"]), 1);    // Need to change
                    return(View(UserVal));
                }
                else if (repUser.EmailIsExist(updateUser.Email, 0) || !Common.IsValidEmail(updateUser.Email))
                {
                    if (!Common.IsValidEmail(updateUser.Email))
                    {
                        ViewBag.messagealert = "Please Enter Valid Email";
                    }
                    else
                    {
                        ViewBag.messagealert = "Email already exist";
                    }
                    ViewBag.UserTitles    = repUser.getDataValues("Title", "0", Convert.ToInt64(Session["UserID"]), 1);         // Need to change
                    ViewBag.Gender        = repUser.getDataValues("Gender", "0", Convert.ToInt64(Session["UserID"]), 1);        // Need to change
                    ViewBag.MaritalStatus = repUser.getDataValues("MaritalStatus", "0", Convert.ToInt64(Session["UserID"]), 1); // Need to change
                    ViewBag.DeviceType    = repUser.getDataValues("DeviceType", "0", Convert.ToInt64(Session["UserID"]), 1);    // Need to change
                    return(View(UserVal));
                }
                else if (repUser.PhoneIsExist(updateUser.Phone, 0))
                {
                    ViewBag.messagealert  = "Phone already exist";
                    ViewBag.UserTitles    = repUser.getDataValues("Title", "0", Convert.ToInt64(Session["UserID"]), 1);         // Need to change
                    ViewBag.Gender        = repUser.getDataValues("Gender", "0", Convert.ToInt64(Session["UserID"]), 1);        // Need to change
                    ViewBag.MaritalStatus = repUser.getDataValues("MaritalStatus", "0", Convert.ToInt64(Session["UserID"]), 1); // Need to change
                    ViewBag.DeviceType    = repUser.getDataValues("DeviceType", "0", Convert.ToInt64(Session["UserID"]), 1);    // Need to change
                    return(View(UserVal));
                }
                else
                {
                    //try
                    //{
                    UserVal.UserID           = repUser.UserIdGeneration();
                    UserVal.Password         = Common.EncryptPassword(updateUser.Password);
                    UserVal.ConfirmPassword  = Common.EncryptPassword(updateUser.ConfirmPassword);
                    UserVal.UserLevel        = "USER";
                    UserVal.IsActive         = true;
                    UserVal.IsTwoFactor      = true;
                    UserVal.ReportingUser    = 1; // Need to change
                    UserVal.RoleID           = 3; // Need to change
                    UserVal.SourceOfCreation = "Sign Up";


                    UserVal.Title         = updateUser.Title;
                    UserVal.FirstName     = updateUser.FirstName;
                    UserVal.MiddleName    = updateUser.MiddleName;
                    UserVal.LastName      = updateUser.LastName;
                    UserVal.Email         = updateUser.Email;
                    UserVal.Phone         = updateUser.Phone;
                    UserVal.Gender        = updateUser.Gender;
                    UserVal.MaritalStatus = updateUser.MaritalStatus;
                    UserVal.DOB           = updateUser.DOB;
                    UserVal.Address       = updateUser.Address;
                    UserVal.LoginName     = updateUser.LoginName;
                    //UserVal.IsTwoFactor = updateUser.IsTwoFactor;
                    UserVal.DeviceID     = updateUser.DeviceID;
                    UserVal.DeviceType   = updateUser.DeviceType;
                    UserVal.UserField1   = updateUser.UserField1;
                    UserVal.UserField2   = updateUser.UserField2;
                    UserVal.UserField3   = updateUser.UserField3;
                    UserVal.CreatedBy    = UserVal.UserID;
                    UserVal.CreatedDate  = DateTime.Now;
                    UserVal.ModifiedBy   = UserVal.UserID;
                    UserVal.ModifiedDate = DateTime.Now;
                    dbEntities.ETUsers.Add(UserVal);
                    dbEntities.SaveChanges();
                    //dbEntities.Entry(UserVal).State = EntityState.Modified;
                    //dbEntities.SaveChanges();

                    ETUserVerified userVerified = new ETUserVerified();
                    userVerified.UserID           = UserVal.UserID;
                    userVerified.IsEmailVefified  = false;
                    userVerified.IsPhoneVerified  = false;
                    userVerified.IsOtherVerified  = false;
                    userVerified.IsOtherVerified1 = false;
                    userVerified.IsOtherVerified2 = false;
                    userVerified.IsOtherVerified3 = false;
                    userVerified.IsActive         = true;
                    userVerified.CreatedBy        = UserVal.UserID;
                    userVerified.CreatedDate      = DateTime.Now;
                    userVerified.ModifiedBy       = UserVal.UserID;
                    userVerified.ModifiedDate     = DateTime.Now;
                    dbEntities.ETUserVerifieds.Add(userVerified);
                    dbEntities.SaveChanges();

                    if (UserVal.UserID != 0)
                    {
                        TempData["messagealert"] = Status.Save;
                    }
                    //}
                    //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    //{
                    //    Exception raise = dbEx;
                    //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    //    {
                    //        foreach (var validationError in validationErrors.ValidationErrors)
                    //        {
                    //            string message = string.Format("{0}:{1}",
                    //                validationErrors.Entry.Entity.ToString(),
                    //                validationError.ErrorMessage);
                    //            // raise a new exception nesting
                    //            // the current instance as InnerException
                    //            raise = new InvalidOperationException(message, raise);
                    //        }
                    //    }
                    //    throw raise;
                    //}
                }
                return(RedirectToAction("Index", "Login"));
            }
            return(View());
        }
Example #3
0
        public ActionResult User_edit(long id, ETUser updateUser)
        {
            TempData["messagealert"] = string.Empty;
            //var errors = ModelState.Values.SelectMany(v => v.Errors);
            if (ModelState.IsValid)
            {
                Userval = new ETUser();
                Userval = repUsers.GetUser(id);

                if (repUsers.LogInNameIsExist(updateUser.LoginName, id))
                {
                    ViewBag.messagealert  = "LogInName already exist";
                    ViewBag.UserTitles    = repUsers.getDataValues("Title", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.Gender        = repUsers.getDataValues("Gender", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.MaritalStatus = repUsers.getDataValues("MaritalStatus", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.UserLevel     = repUsers.getDataValues("UserLevel", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.ReportingUser = repUsers.getMappedReportingUser();
                    ViewBag.DeviceType    = repUsers.getDataValues("DeviceType", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.Role          = repUsers.getRole();
                    return(View(Userval));
                }
                else if (repUsers.EmailIsExist(updateUser.Email, id) || !Common.IsValidEmail(updateUser.Email))
                {
                    if (!Common.IsValidEmail(updateUser.Email))
                    {
                        ViewBag.messagealert = "Please Enter Valid Email";
                    }
                    else
                    {
                        ViewBag.messagealert = "Email already exist";
                    }
                    ViewBag.UserTitles    = repUsers.getDataValues("Title", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.Gender        = repUsers.getDataValues("Gender", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.MaritalStatus = repUsers.getDataValues("MaritalStatus", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.UserLevel     = repUsers.getDataValues("UserLevel", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.ReportingUser = repUsers.getMappedReportingUser();
                    ViewBag.DeviceType    = repUsers.getDataValues("DeviceType", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.Role          = repUsers.getRole();
                    return(View(Userval));
                }
                else if (repUsers.PhoneIsExist(updateUser.Phone, id))
                {
                    ViewBag.messagealert  = "Phone already exist";
                    ViewBag.UserTitles    = repUsers.getDataValues("Title", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.Gender        = repUsers.getDataValues("Gender", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.MaritalStatus = repUsers.getDataValues("MaritalStatus", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.UserLevel     = repUsers.getDataValues("UserLevel", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.ReportingUser = repUsers.getMappedReportingUser();
                    ViewBag.DeviceType    = repUsers.getDataValues("DeviceType", Session["UserLevel"].ToString(), Convert.ToInt64(Session["UserID"]), Convert.ToInt64(Session["ReportingUser"]));
                    ViewBag.Role          = repUsers.getRole();
                    return(View(Userval));
                }
                else
                {
                    long UserId = Convert.ToInt64(Session["UserID"]);
                    Userval.Title           = updateUser.Title;
                    Userval.FirstName       = updateUser.FirstName;
                    Userval.MiddleName      = updateUser.MiddleName;
                    Userval.LastName        = updateUser.LastName;
                    Userval.Email           = updateUser.Email;
                    Userval.Phone           = updateUser.Phone;
                    Userval.Gender          = updateUser.Gender;
                    Userval.MaritalStatus   = updateUser.MaritalStatus;
                    Userval.DOB             = updateUser.DOB;
                    Userval.Address         = updateUser.Address;
                    Userval.RoleID          = updateUser.RoleID;
                    Userval.LoginName       = updateUser.LoginName;
                    Userval.Password        = Common.EncryptPassword(updateUser.Password);
                    Userval.ConfirmPassword = Common.EncryptPassword(updateUser.ConfirmPassword);
                    //Userval.Password = updateUser.Password;
                    Userval.IsTwoFactor   = updateUser.IsTwoFactor;
                    Userval.UserLevel     = updateUser.UserLevel;
                    Userval.ReportingUser = updateUser.ReportingUser;
                    //Userval.IsOwner = updateUser.IsOwner;
                    //Userval.IsAdmin = updateUser.IsAdmin;
                    //Userval.IsManager = updateUser.IsManager;
                    Userval.IsActive                = updateUser.IsActive;
                    Userval.DeviceID                = updateUser.DeviceID;
                    Userval.DeviceType              = updateUser.DeviceType;
                    Userval.UserField1              = updateUser.UserField1;
                    Userval.UserField2              = updateUser.UserField2;
                    Userval.UserField3              = updateUser.UserField3;
                    Userval.ModifiedBy              = UserId;
                    Userval.ModifiedDate            = DateTime.Now;
                    dbEntities.Entry(Userval).State = EntityState.Modified;
                    dbEntities.SaveChanges();

                    var userVerify = dbEntities.ETUserVerifieds.Where(x => x.UserID == Userval.UserID && x.IsActive).FirstOrDefault();
                    if (userVerify == null)
                    {
                        ETUserVerified userVerified = new ETUserVerified();
                        userVerified.UserID           = Userval.UserID;
                        userVerified.IsEmailVefified  = false;
                        userVerified.IsPhoneVerified  = false;
                        userVerified.IsOtherVerified  = false;
                        userVerified.IsOtherVerified1 = false;
                        userVerified.IsOtherVerified2 = false;
                        userVerified.IsOtherVerified3 = false;
                        userVerified.IsActive         = true;
                        userVerified.CreatedBy        = UserId;
                        userVerified.CreatedDate      = DateTime.Now;
                        userVerified.ModifiedBy       = UserId;
                        userVerified.ModifiedDate     = DateTime.Now;
                        dbEntities.ETUserVerifieds.Add(userVerified);
                        dbEntities.SaveChanges();
                    }

                    if (Userval.UserID != 0)
                    {
                        TempData["messagealert"] = Status.Update;
                    }
                }
                return(RedirectToAction("Index", "User"));
            }
            return(View());
        }