Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ActionResult AddEditUser(int userId = 0)
        {
            //var datataaa = EmailDesigner.GetAccountActivationEmail("asd","IDSISSSSSSS");

            var userModel = new UserViewModel();

            var countryList = CountryList.GetCountryList();

            if (countryList.Any())
            {
                if (countryList.Count > 0)
                {
                    ViewBag.DropDownForCountry =
                        countryList.Select(c => new SerializableSelectListItem
                        {
                            Text = c.CountryName,
                            Value = c.CountryId.ToString(CultureInfo.InvariantCulture)
                        });
                }
            }

            if (SessionManager.GetSessionInfo() != null && (SessionManager.IsAdminLoggedIn() || SessionManager.GetSessionInfo().Id == userId))
            {

                if (userId > 0)
                {
                    userModel = UserManager.GetUserById(userId);

                }

                if (userModel.Country != 0)
                {
                    ViewBag.StateInfo = StateList.GetStateByCountry(userModel.Country);
                }

                if (SessionManager.IsAdminLoggedIn())
                    ViewBag.Roles = NewsIndiaBAL.RoleManager.GetRoles();

            }
            else if (SessionManager.GetSessionInfo() != null)
                return RedirectToAction("Index", "Home");

            ViewBag.IsAddRequest = userModel.UserId == 0;

            return View(userModel);
            //  return RedirectToAction("Index", "Home");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Used to save the User Information
        /// </summary>
        /// <returns></returns>
        public static int SaveUserInformation(UserViewModel um, bool requestForPasswordChange, bool isAdminSave,
            int? loggedInUser = null)
        {
            try
            {
                using (var nie = new NewsIndiaTVEntities())
                {
                    if (um.UserId != 0)
                    {
                        var userInfo = nie.UserMasters.FirstOrDefault(m => m.Id == um.UserId & m.IsActive);
                        if (userInfo != null)
                        {

                            userInfo.FirstName = um.FirstName;
                            userInfo.LastName = um.LastName;
                            userInfo.MiddleName = um.MiddleName;
                            userInfo.Gender = um.Gender;
                           // userInfo.Email = um.EmailId;
                            userInfo.PhoneNumber = um.MobileNumber;
                            userInfo.DateOfBirth = um.DateOfBirth;

                            if (requestForPasswordChange)
                                userInfo.Password = um.Password;

                            userInfo.Address = um.Address;
                            userInfo.City = um.City;
                            userInfo.StateID = um.State;
                            userInfo.CountryID = um.Country;
                            userInfo.Pincode = um.PinCode;
                            userInfo.ModifiedBy = loggedInUser;
                            userInfo.ModifiedOn = DateTime.Now;
                            if (isAdminSave)
                            {
                                userInfo.RoleId = um.SelectedRoleId;
                                userInfo.IsEnabled = um.IsEnabled;
                            }
                            nie.SaveChanges();
                            return userInfo.Id;
                        }
                        return 0;

                    }
                    else
                    {
                        var userData = new UserMaster()
                         {

                             FirstName = um.FirstName,
                             LastName = um.LastName,
                             MiddleName = um.MiddleName,
                             Gender = um.Gender,
                             Email = um.EmailId,
                             Password = um.Password,
                             PhoneNumber = um.MobileNumber,
                             Address = um.Address,
                             City = um.City,
                             StateID = um.State,
                             CountryID = um.Country,
                             Pincode = um.PinCode,
                             IsActive = true,
                             CreatedBy = loggedInUser,
                             CreatedOn = DateTime.Now,
                             ModifiedBy = loggedInUser,
                             ModifiedOn = DateTime.Now,
                             DateOfBirth = um.DateOfBirth

                         };

                        if (isAdminSave)
                        {
                            userData.RoleId = um.SelectedRoleId;
                            userData.IsEnabled = um.IsEnabled;
                        }
                        else
                        {
                            userData.RoleId = 3;
                            userData.IsEnabled = false;
                        }
                        nie.UserMasters.Add(userData);
                        nie.SaveChanges();
                        return userData.Id;
                    }

                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
Exemplo n.º 3
0
        public ActionResult AddEditUser(UserViewModel userInfo)
        {
            if (ModelState.IsValid)
            {
                var userId = userInfo.UserId;
                var userIdSaved = NewsIndiaBAL.UserManager.SaveUserInformation(userInfo, false, SessionManager.IsAdminLoggedIn(), SessionManager.GetSessionInfo() != null ? SessionManager.GetSessionInfo().Id : 0);

                if (userId == 0 && (userIdSaved > 0))
                {
                    string uniqueGuid = System.Guid.NewGuid().ToString();
                    NewsIndiaBAL.AuthenticationLinkManager.CreateAuthenticationLink(uniqueGuid, 1, userIdSaved);
                    var emailTemplate = EmailDesigner.GetAccountActivationEmail(userInfo.FirstName, uniqueGuid);
                    Common.EmailHelper.SendEmail("News India Admin", new List<string>() { userInfo.EmailId }, "Account Activation", emailTemplate);
                }

                if (SessionManager.IsAdminLoggedIn())
                    return RedirectToAction("Index", "UserManager");
                else if (SessionManager.GetSessionInfo() != null)
                    return RedirectToAction("Index", "Home");
                else
                    return RedirectToAction("AccountCreated", "UserManager");
            }
            return View(userInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Used to save the information of the user
        /// </summary>
        /// <returns></returns>
        public static int SaveUserInformation(UserViewModel userInfo, bool requestForPasswordChange, bool isAdminSave, int? loggedInUserId)
        {
            try
            {
                if (loggedInUserId == 0)
                    loggedInUserId = null;

                var userId = userInfo.UserId;
                if (userId == 0)
                    userInfo.Password = new Common.EncryptionHelper().Encrypt(userInfo.Password);

                var userIdSaved = NewsIndiaDAL.UserManager.SaveUserInformation(userInfo, requestForPasswordChange, isAdminSave, loggedInUserId);

                return userIdSaved;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }