public long SaveUserMaster(List<UserMaster> userData)
        {
            long userId = 0;
            using (var context = new TheThinkerz_WTPSharePointEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {

                        tblUser objUser = new tblUser();
                        foreach (UserMaster objItem in userData)
                        {
                            objUser.EmailId = objItem.EmailId;
                            objUser.FirstName = objItem.FirstName;
                            objUser.LastName = objItem.LastName;
                            objUser.Address1 = objItem.Address1;
                            objUser.Address2 = objItem.Address2;
                            objUser.ZipCode = objItem.ZipCode;
                            objUser.CityName = objItem.CityName;
                            objUser.StateId = objItem.StateId;
                            objUser.PrimaryPhoneNo = objItem.PrimaryPhoneNo;
                            objUser.PrimaryPhoneType = objItem.PrimaryPhoneType;
                            objUser.PrimaryMobileProvider = objItem.PrimaryMobileProvider;
                            objUser.SecondaryPhoneNo = objItem.SecondaryPhoneNo;
                            objUser.SecondaryPhoneType = objItem.SecondaryPhoneType;
                            objUser.SecondaryMobileProvider = objItem.SecondaryMobileProvider;
                            objUser.PrefferedContactMethod = objItem.PrefferedContactMethod;
                            objUser.CreateDate = objItem.CreateDate;
                            objUser.UpdateDate = objItem.UpdateDate;
                            objUser.PinNo = objItem.PinNo;
                            objUser.Active = objItem.Active;
                            context.tblUsers.Add(objUser);
                        }
                        context.SaveChanges();
                        context.Entry(objUser).GetDatabaseValues();
                        userId = objUser.UserID;
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            return userId;
        }
        public bool SaveUserRequest(UserRequest requestData, RequestStatus statusData, List<DocRepository> documentData)
        {
            long requestId = 0;
            long statusId = 0; long docId = 0;
            using (var context = new TheThinkerz_WTPSharePointEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        tblUserRequest objUserRequest = new tblUserRequest();
                        var sql = "SELECT COUNT(1) FROM dbo.tblUserRequest where RequestId=" + requestData.RequestId;
                        var count = context.Database.SqlQuery<int>(sql).Single();
                        if (count == 0)
                        {
                            requestData.RequestNo = GenerateRequestNo();

                            objUserRequest.RequestNo = requestData.RequestNo;
                            objUserRequest.FirstName = requestData.FirstName;
                            objUserRequest.LastName = requestData.LastName;
                            objUserRequest.Address1 = requestData.Address1;
                            objUserRequest.Address2 = requestData.Address2;
                            objUserRequest.ZipCode = requestData.ZipCode;
                            objUserRequest.CityName = requestData.CityName;
                            objUserRequest.StateId = requestData.StateId;
                            objUserRequest.PrimaryPhoneNo = requestData.PrimaryPhoneNo;
                            objUserRequest.PrimaryPhoneType = requestData.PrimaryPhoneType;
                            objUserRequest.PrimaryMobileProvider = requestData.PrimaryMobileProvider;
                            objUserRequest.SecondaryPhoneNo = requestData.SecondaryPhoneNo;
                            objUserRequest.SecondaryPhoneType = requestData.SecondaryPhoneType;
                            objUserRequest.SecondaryMobileProvider = requestData.SecondaryMobileProvider;
                            objUserRequest.EmailId = requestData.EmailId;
                            objUserRequest.PrefContactMethod = requestData.PrefContactMethod;
                            objUserRequest.ProblemLocation = requestData.ProblemLocation;
                            objUserRequest.ShortDescription = requestData.ShortDescription;
                            objUserRequest.LongDescription = requestData.LongDescription;
                            objUserRequest.AttachedDocName = requestData.AttachedDocName;
                            objUserRequest.EmailConfirmation = requestData.EmailConfirmation;
                            objUserRequest.CreateDate = requestData.CreateDate;
                            objUserRequest.UpdateDate = requestData.UpdateDate;
                            objUserRequest.Status = requestData.Status;
                            context.tblUserRequests.Add(objUserRequest);
                        }
                        else
                        {
                            objUserRequest = context.tblUserRequests.Where(r => r.RequestId == requestData.RequestId).Single<tblUserRequest>(); ;
                            objUserRequest.ProblemLocation = requestData.ProblemLocation;
                            objUserRequest.ShortDescription = requestData.ShortDescription;
                            objUserRequest.LongDescription = requestData.LongDescription;
                            objUserRequest.EmailConfirmation = requestData.EmailConfirmation;
                            objUserRequest.Status = requestData.Status;
                            objUserRequest.UpdateDate = requestData.UpdateDate;

                        }

                        context.SaveChanges();
                        context.Entry(objUserRequest).GetDatabaseValues();
                        requestId = objUserRequest.RequestId;

                        tblDocRepository objDocRepository = new tblDocRepository();
                        foreach (DocRepository objItem in documentData)
                        {
                            objItem.RequestId = requestId;
                            var sqlDoc = "SELECT COUNT(1) FROM dbo.tblDocRepository where RecId=" + objItem.RecId;
                            var countDoc = context.Database.SqlQuery<int>(sqlDoc).Single();
                            if (countDoc == 0)
                            {
                                objDocRepository.RequestId = objItem.RequestId;
                                objDocRepository.FileName = objItem.FileName;
                                objDocRepository.FilePath = objItem.FilePath;
                                objDocRepository.UploadDate = objItem.UploadDate;

                                context.tblDocRepositories.Add(objDocRepository);
                                context.SaveChanges();
                            }
                            docId++;
                        }

                        tblRequestStatu objRequestStatus = new tblRequestStatu();

                        statusData.RequestId = requestId;
                        var sqlStatus = "SELECT COUNT(1) FROM dbo.tblRequestStatus where RecordId=" + statusData.RecordId;
                        var countStatus = context.Database.SqlQuery<int>(sqlStatus).Single();
                        if (countStatus == 0)
                        {
                            objRequestStatus.RequestId = statusData.RequestId;
                            objRequestStatus.Status = statusData.Status;
                            objRequestStatus.UpdateDate = statusData.UpdateDate;
                            objRequestStatus.UpdateBy = statusData.UpdateBy;

                            context.tblRequestStatus.Add(objRequestStatus);
                        }
                        context.SaveChanges();
                        if (statusData != null)
                        {
                            context.Entry(objRequestStatus).GetDatabaseValues();
                            statusId = objRequestStatus.RecordId;
                        }
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
            return requestId > 0 && statusId > 0 && documentData.Count == docId;
        }
        public int SaveLoginHistory(List<LoginHistory> data)
        {
            int returnValue = 0;
            using (var context = new TheThinkerz_WTPSharePointEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {

                        foreach (LoginHistory objItem in data)
                        {

                            var count = context.tblLoginHistories.Count(r => r.RecordId == objItem.RecordId);
                            if (count == 0)
                            {
                                tblLoginHistory objLoginHistory = new tblLoginHistory();
                                PropertyInfo[] userProperties = objLoginHistory.GetType().GetProperties().Where(p => p.GetMethod.IsVirtual == false).ToArray(); ;
                                foreach (PropertyInfo item in userProperties)
                                {
                                    PropertyInfo dataProperty = objItem.GetType().GetProperty(item.Name, BindingFlags.Public | BindingFlags.Instance);
                                    item.SetValue(objLoginHistory, dataProperty.GetValue(objItem), null);
                                }
                                context.tblLoginHistories.Add(objLoginHistory);
                            }
                        }
                        returnValue = context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            return returnValue;
        }