Beispiel #1
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;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Used to Set The User Information in the Session
 /// </summary>
 /// <param name="usreInfo"></param>
 /// <returns></returns>
 public static bool SetSessionInfo(UserMaster usreInfo)
 {
     if (HttpContext.Current.Session["USER_INFORMATION"] == null)
     {
         HttpContext.Current.Session.Add("USER_INFORMATION", usreInfo);
     }
     return true;
 }