public bool CanAccess(int rpcId, CMDDatabaseContext context)
        {
            if (!_accessCache.ContainsKey(rpcId))
            {
                return(false);
            }

            // var userRoles = GetUserRoleIds(userId);
            var userRoles = context.SecurityContext.User.Roles.Select(x => x.Id).ToList();

            return(_accessCache[rpcId].Intersect(userRoles).Any());
        }
Example #2
0
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var exceptionLog = new CMDExceptionLog
            {
                CMDAuditLogId    = _auditLogId,
                ExceptionLogDate = _exceptionLogDate,
                InnerException   = _innerException,
                Message          = _message,
                StackTrace       = _stackTrace
            };

            return(context.Create(exceptionLog, false) as T);
        }
 /// <summary>
 /// This method return a query to select customer source track
 /// </summary>
 /// <param name="context">Database context</param>
 /// <param name="practiceId">Practice id to get source track</param>
 /// <returns>Return a query to get practice source track</returns>
 private static IQueryable <CMDDashboardSourceRecord> CreateSelectQuery(CMDDatabaseContext context, int practiceId)
 {
     return(context.CMDPracticeSourceTracks.Where(cmdPracticeSourceTrack => cmdPracticeSourceTrack.IsActive &&
                                                  cmdPracticeSourceTrack.CMDPracticeID == practiceId)
            .Select(cmdPracticeSourceTrack => new CMDDashboardSourceRecord
     {
         CMDBusinessUnitName = context.CMDBusinessUnits
                               .Where(cmdBusinessUnit => cmdBusinessUnit.IsActive &&
                                      cmdBusinessUnit.Id == cmdPracticeSourceTrack.BusinessUnitID).FirstOrDefault().Name,
         SourceRecordID = cmdPracticeSourceTrack.SourceRecordID,
         CreatedDate = cmdPracticeSourceTrack.CreatedDate
     }).Distinct());
 }
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var cmdCustomer = new CMDCustomerDuplicateMap
            {
                DuplicateCustomerID = _duplicateCustomerID,
                ExistingCustomerID  = _existingCustomerID,
                CreatedDate         = DateTime.UtcNow,
                UpdatedBy           = ALPHAEON.CMD.Common.Constants.Configuration.UpdatedBy,
                UpdatedDate         = DateTime.UtcNow
            };

            return(context.Create(cmdCustomer, false) as T);
        }
Example #5
0
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var user = context.Users.FirstOrDefault(x => x.Email == _email);

            if (user != null)
            {
                return(user as T);
            }

            var createUser = new CreateUserRunnable(_firstName, _lastName, _email);

            return(context.ExecuteRunnable <T>(createUser));
        }
Example #6
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Method != HttpMethod.Get)
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var principal = request.GetUserPrincipal() as ApiPrincipal;

            if (principal == null)
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var query = request.RequestUri.Query;

            if (!MyUserIdInjector.HasOccurences(query))
            {
                return(base.SendAsync(request, cancellationToken));
            }

            var logger = HttpContext.Current.Items[WebApiConfig.LoggerHttpContextItemsKey] as ILogger;

            try
            {
                using (var context = CMDDatabaseContext.GetContextWithAccessToken(principal.AccessToken, logger))
                {
                    var userId = context.GetCurrentUser().Id;

                    var injector = new MyUserIdInjector(userId);

                    if (!injector.TryParseOccurences(query, out query))
                    {
                        return(base.SendAsync(request, cancellationToken));
                    }
                }

                var uri = new UriBuilder(request.RequestUri)
                {
                    Query = query.TrimStart(new[] { '?' })
                };
                request.RequestUri = uri.Uri;
            }
            catch (Exception ex)
            {
                CMDApiLogger.LogException(ex, EventCategory.HttpHandlers, EventLogEntryType.Warning);
            }

            return(base.SendAsync(request, cancellationToken));
        }
Example #7
0
 /// <summary>
 /// Create query to get the list of practice by selecte practice
 /// </summary>
 /// <param name="context">Database context</param>
 /// <param name="stateId">Selected state id</param>
 /// <returns>query to fetch the list of practice</returns>
 private static IQueryable <CMDPractice> CreateSelectQuery(CMDDatabaseContext context, int stateId)
 {
     return(context.CMDPractices
            .Join(
                context.CMDPracticeContactMaps,
                recPractice => recPractice.Id,
                cmdPracticeContactMap => cmdPracticeContactMap.CMDPracticeID,
                (recPractice, cmdPracticeContactMap) => new { recPractice, cmdPracticeContactMap })
            .Where(record => record.cmdPracticeContactMap.IsActive &&
                   record.cmdPracticeContactMap.CMDContact.CMDStateID == stateId &&
                   record.cmdPracticeContactMap.CMDContact.CMDState.IsActive &&
                   record.cmdPracticeContactMap.CMDContact.IsActive)
            .Select(record => record.cmdPracticeContactMap.CMDPractice).Distinct());
 }
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0) where T : class
        {
            context.Configuration.LazyLoadingEnabled = false;

            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            List <CMDDashboardCustomer> existingCustomerListResult = null;

            try
            {
                IQueryable <CMDDashboardCustomer> cmdDashboardExistingCustomerList = CreateSelectQuery(context);

                if (!string.IsNullOrEmpty(whereCondition))
                {
                    cmdDashboardExistingCustomerList = cmdDashboardExistingCustomerList.Where(whereCondition);
                }

                existingCustomerListResult = cmdDashboardExistingCustomerList.ToList();

                if (existingCustomerListResult != null)
                {
                    existingCustomerListResult =
                        cmdDashboardExistingCustomerList.ToList()
                        .GroupBy(existingCustomer => existingCustomer.CustomerID)
                        .Select(recordCustomer => recordCustomer.First()).ToList();

                    var countCustomer = existingCustomerListResult.Count();

                    #region Order By Condition
                    orderByCondition = !string.IsNullOrEmpty(orderByCondition) ? orderByCondition : "CustomerID";
                    cmdDashboardExistingCustomerList = cmdDashboardExistingCustomerList.OrderBy(orderByCondition).Skip(skip).Take(take);
                    #endregion

                    existingCustomerListResult =
                        cmdDashboardExistingCustomerList.ToList()
                        .GroupBy(existingCustomer => existingCustomer.CustomerID)
                        .Select(recordCustomer => recordCustomer.First()).ToList();

                    existingCustomerListResult.All(m => { m.CustomersCount = countCustomer; return(true); });
                }

                CMDLogger.LogAudit("Obtained the Customers List having Duplicate Customers record in CMD", ALPHAEON.CMD.Common.Constants.General.ApplicationName);
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(existingCustomerListResult as List <T>);
        }
Example #9
0
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0, string queryParameters = null) where T : class
        {
            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            context.Configuration.LazyLoadingEnabled = false;
            List <CMDDashboardCustomerPractice> customerPracticeListResult = null;

            int customerId = Convert.ToInt32(queryParameters);

            if (customerId <= 0)
            {
                return(customerPracticeListResult as List <T>);
            }

            try
            {
                IQueryable <CMDDashboardCustomerPractice> cmdDashboardCustomerPracticeList = CreateSelectQuery(context, customerId);

                if (!string.IsNullOrEmpty(whereCondition))
                {
                    cmdDashboardCustomerPracticeList = cmdDashboardCustomerPracticeList.Where(whereCondition);
                }

                var countPractice = cmdDashboardCustomerPracticeList.Count();

                //// Fetch all the practice if parameter take is 0
                if (take == 0)
                {
                    take = countPractice;
                }

                if (!string.IsNullOrEmpty(orderByCondition))
                {
                    cmdDashboardCustomerPracticeList = cmdDashboardCustomerPracticeList.OrderBy(orderByCondition).Skip(skip).Take(take);
                }
                else
                {
                    cmdDashboardCustomerPracticeList = cmdDashboardCustomerPracticeList.OrderBy("Id").Skip(skip).Take(take);
                }

                customerPracticeListResult = cmdDashboardCustomerPracticeList.ToList();
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(customerPracticeListResult as List <T>);
        }
Example #10
0
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0, string queryParameters = null) where T : class
        {
            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            context.Configuration.LazyLoadingEnabled = false;

            int customerId = Convert.ToInt32(queryParameters);

            List <CMDSpeciality> customerSpecialityListResult = null;

            try
            {
                IQueryable <CMDSpeciality> cmdDashboardCustomerSpecialityList =
                    context.CMDCustomerSpecialityMaps
                    .Where(recCMDCustomerSpecialityMap => recCMDCustomerSpecialityMap.IsActive == true &&
                           recCMDCustomerSpecialityMap.CMDCustomerID == customerId &&
                           recCMDCustomerSpecialityMap.CMDCustomer.IsActive == true)
                    .Select(recordCustomerSpecialityMap => recordCustomerSpecialityMap.CMDSpeciality);

                if (!string.IsNullOrEmpty(whereCondition))
                {
                    cmdDashboardCustomerSpecialityList = cmdDashboardCustomerSpecialityList.Where(whereCondition);
                }

                var countSpeciality = cmdDashboardCustomerSpecialityList.Count();

                if (take == 0)
                {
                    take = countSpeciality;
                }

                if (!string.IsNullOrEmpty(orderByCondition))
                {
                    cmdDashboardCustomerSpecialityList = cmdDashboardCustomerSpecialityList.OrderBy(orderByCondition).Skip(skip).Take(take);
                }
                else
                {
                    cmdDashboardCustomerSpecialityList = cmdDashboardCustomerSpecialityList.OrderBy("Id").Skip(skip).Take(take);
                }

                customerSpecialityListResult = cmdDashboardCustomerSpecialityList.ToList();
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(customerSpecialityListResult as List <T>);
        }
        public override void Validate()
        {
            if (string.IsNullOrWhiteSpace(this.Model.Email))
            {
                return;
            }

            using (var context = CMDDatabaseContext.GetContext())
            {
                if (context.Users.Any(u => u.Email == this.Model.Email))
                {
                    throw new InvalidDataException("Email address is already in use!");
                }
            }
        }
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var distributorLog = new CMDDistributor
            {
                Name         = _name.RemoveQuotes(),
                CMDContactID = _cmdContactID,
                Description  = _description.RemoveQuotes(),
                CreatedDate  = _createdDate,
                UpdatedDate  = _updatedDate,
                IsActive     = _isActive,
                UpdatedBy    = _updatedBy.RemoveQuotes()
            };

            return(context.Create(distributorLog, false) as T);
        }
Example #13
0
 public override void Validate()
 {
     using (var context = CMDDatabaseContext.GetContext())
     {
         //todo: Question - is the following navigation possible?
         var collectionFilter = context.CollectionFilters.FirstOrDefault(c => c.Id == this.Model.CollectionFilterId);
         if (collectionFilter == null)
         {
             throw new InvalidDataException("Invalid CollectionFilterId.");
         }
         if (context.ApplicationCollectionFilters.Any(x => x.CollectionFilter.ModelClassId == collectionFilter.ModelClassId && x.ApplicationId == this.Model.ApplicationId))
         {
             throw new InvalidDataException("Application already has a CollectionFilter applied to this model class.");
         }
     }
 }
        /// <summary>
        /// This method returns a list of CMDDashboardSourceRecord for the practice whose Id is passed.
        /// </summary>
        /// <typeparam name="T">Type of object returned by RPC, here CMDDashboardSourceRecord</typeparam>
        /// <param name="context">Obj. of CMDDatabaseContext</param>
        /// <param name="whereCondition">where condition string</param>
        /// <param name="orderByCondition">order by condition string</param>
        /// <param name="skip">No. of records to be skipped</param>
        /// <param name="take">No. of records to be taken</param>
        /// <param name="queryParameters">PracticeId</param>
        /// <returns></returns>
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0, string queryParameters = null) where T : class
        {
            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            context.Configuration.LazyLoadingEnabled = false;
            List <CMDDashboardSourceRecord> cmdPracticedSourceRecordListResult = null;

            try
            {
                if (!string.IsNullOrEmpty(queryParameters))
                {
                    int practiceId = Convert.ToInt32(queryParameters);

                    if (practiceId <= 0)
                    {
                        return(cmdPracticedSourceRecordListResult as List <T>);
                    }

                    IQueryable <CMDDashboardSourceRecord> cmdDashboardSourceRecordList = CreateSelectQuery(context, practiceId);

                    if (!string.IsNullOrEmpty(whereCondition))
                    {
                        cmdDashboardSourceRecordList = cmdDashboardSourceRecordList.Where(whereCondition);
                    }

                    if (!string.IsNullOrEmpty(orderByCondition))
                    {
                        cmdDashboardSourceRecordList = cmdDashboardSourceRecordList.OrderBy(orderByCondition).Skip(skip).Take(take);
                    }
                    else
                    {
                        cmdDashboardSourceRecordList = cmdDashboardSourceRecordList.OrderBy("CreatedDate").Skip(skip).Take(take);
                    }

                    cmdPracticedSourceRecordListResult = cmdDashboardSourceRecordList.ToList();

                    CMDLogger.LogAudit(string.Format("Obtained the CMD Source Track Record List by {0} ID from CMD", ALPHAEON.CMD.Common.Enums.Entity.CMDPractice), ALPHAEON.CMD.Common.Constants.General.ApplicationName);
                }
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(cmdPracticedSourceRecordListResult as List <T>);
        }
Example #15
0
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0, string queryParameters = null) where T : class
        {
            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            context.Configuration.LazyLoadingEnabled = false;

            List <EntityExist> entityExistList = new List <EntityExist>();

            try
            {
                if (!string.IsNullOrEmpty(queryParameters))
                {
                    //// Split the comma "," seperated parameters
                    string[] parameters     = queryParameters.Split(',');
                    int      sourceRecordId = Convert.ToInt32(parameters[0]);
                    int      businessUnitId = Convert.ToInt32(parameters[1]);
                    int      entityId       = Convert.ToInt32(parameters[2]);
                    string   npi            = string.Empty;

                    if (parameters.Count() == 4)
                    {
                        if (!string.IsNullOrEmpty(parameters[3]))
                        {
                            npi = parameters[3];
                        }
                    }

                    if (entityId == (int)ALPHAEON.CMD.Common.Enums.Entity.CMDCustomer)
                    {
                        entityExistList.Add(ValidateCustomer(context, sourceRecordId, businessUnitId, npi));
                    }
                    else if (entityId == (int)ALPHAEON.CMD.Common.Enums.Entity.CMDPractice)
                    {
                        entityExistList.Add(ValidatePractice(context, sourceRecordId, businessUnitId));
                    }
                }
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(entityExistList as List <T>);
        }
Example #16
0
        private void RefreshCacheForCollectionFilterId(int collectionFilterId)
        {
            using (var context = CMDDatabaseContext.GetContext())
            {
                var collectionFilter = context.CollectionFilters.FirstOrDefault(x => x.Id == collectionFilterId);
                if (collectionFilter == null)
                {
                    throw new InvalidDataException();
                }

                var collectionFilterCache = new CollectionFilterCacheModel
                {
                    CollectionFilter = collectionFilter,
                    ModelClassId     = collectionFilter.ModelClassId
                };

                _cache.TryAdd(collectionFilterId, collectionFilterCache);
            }
        }
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var practice = new CMDPractice
            {
                PracticeName           = _practiceName,
                PrimaryOwnerID         = _primaryOwnerID,
                CMDLegalJurisdictionID = _cmdLegalJurisdictionID,
                OriginalBusinessUnitID = _originalBusinessUnitID,
                IsActive    = _isActive,
                Email       = _email,
                Phone       = _phone,
                IsDuplicate = _isDuplicate,
                UpdatedDate = _updatedDate,
                CreatedDate = _createdDate,
                UpdatedBy   = _updatedBy
            };

            return(context.Create(practice, false) as T);
        }
Example #18
0
        public override void Validate()
        {
            var titleKey = DAL.PropertyName <CollectionFilter>(x => x.Title);

            if (!this.Delta.ContainsKey(titleKey))
            {
                return;
            }

            var newTitle = this.Delta[titleKey].ToString();

            using (var context = CMDDatabaseContext.GetContext())
            {
                if (context.CollectionFilters.Any(c => c.Title == newTitle && c.ModelClassId == this.Model.ModelClassId))
                {
                    throw new InvalidDataException("CollectionFilter Title must be unique per ModelClass.");
                }
            }
        }
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var practiceAndAccount = new CMDAccount
            {
                Name                   = _name,
                CMDPracticeID          = _cmdPracticeID,
                FedTaxID               = _fexTaxID,
                CMDAccountTypeID       = Convert.ToInt32(_cmdAccountTypeID),
                NetSuiteID             = _netSuiteID,
                OriginalBusinessUnitID = _originalBusinessUnitID,
                OriginalDistributorID  = _originalDistributorID,
                IsActive               = _isActive,
                UpdatedDate            = _updatedDate,
                CreatedDate            = _createdDate,
                UpdatedBy              = _updatedBy,
                CMDBusinessUnitId      = _CMDBusinessUnitID
            };

            return(context.Create(practiceAndAccount, false) as T);
        }
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0) where T : class
        {
            context.Configuration.LazyLoadingEnabled = false;

            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            List <CMDDashboardPractice> existingPracticeListResult = null;

            try
            {
                IQueryable <CMDDashboardPractice> cmdDashboardExistingPracticeList = CreateSelectQuery(context);

                if (!string.IsNullOrEmpty(whereCondition))
                {
                    cmdDashboardExistingPracticeList = cmdDashboardExistingPracticeList.Where(whereCondition);
                }

                //// Order By Condition
                orderByCondition = !string.IsNullOrEmpty(orderByCondition) ? orderByCondition : "Id";
                cmdDashboardExistingPracticeList = cmdDashboardExistingPracticeList.OrderBy(orderByCondition).Skip(skip).Take(take);

                existingPracticeListResult = cmdDashboardExistingPracticeList.ToList();

                if (existingPracticeListResult != null)
                {
                    existingPracticeListResult =
                        cmdDashboardExistingPracticeList.ToList()
                        .GroupBy(existingPractice => existingPractice.Id)
                        .Select(recordPractice => recordPractice.First()).ToList();
                }

                CMDLogger.LogAudit("Obtained the Duplicate Practices List by Practice ID from CMD", ALPHAEON.CMD.Common.Constants.General.ApplicationName);
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(existingPracticeListResult as List <T>);
        }
Example #21
0
        /// <summary>
        /// Check which group for given business unit id belongs
        /// Get all business units belong to cmdSourceGroup Group
        /// If no id is there for same businessunit, check that Sourceid for other businessunits belong to same group
        /// Then we will return that only source record need to insert with same cmdPracticeid.
        /// </summary>
        /// <param name="context">Current database context</param>
        /// <param name="sourceRecordId">Current source record id</param>
        /// <param name="businessUnitId">Current business unit id</param>
        /// <returns>Practice Id : If for same business unit that id practice is already exist, NULL: If for same business unit that id practice is not exist</returns>
        private int?GetExistingCMDPracticeIdForSameGroup(CMDDatabaseContext context, int sourceRecordId, int businessUnitId)
        {
            int?existingCMDPracticeIdforSameGroup = null;

            if (!IsPracticeExistforSameBusinessUnit(context, sourceRecordId, businessUnitId))
            {
                existingCMDPracticeIdforSameGroup = context.CMDPracticeSourceTracks.Where(cmdPracticeSourceTrackRecord => cmdPracticeSourceTrackRecord.IsActive &&
                                                                                          cmdPracticeSourceTrackRecord.SourceRecordID == sourceRecordId &&
                                                                                          context.CMDSourceGroupCMDBusinessUnitMaps.Where(cmdSourceGroupCMDBusinessUnitMap =>
                                                                                                                                          cmdSourceGroupCMDBusinessUnitMap.CMDBusinessUnitID != businessUnitId && cmdSourceGroupCMDBusinessUnitMap.IsActive &&
                                                                                                                                          cmdSourceGroupCMDBusinessUnitMap.CMDSourceGroupID == context.CMDSourceGroupCMDBusinessUnitMaps
                                                                                                                                          .Where(cmdSourceGroupCMDBusinessUnitMapRecord => cmdSourceGroupCMDBusinessUnitMapRecord.CMDBusinessUnitID == businessUnitId &&
                                                                                                                                                 cmdSourceGroupCMDBusinessUnitMapRecord.IsActive && cmdSourceGroupCMDBusinessUnitMapRecord.CMDSourceGroup.IsActive)
                                                                                                                                          .Select(cmdSourceGroupCMDBusinessUnitMapRecord => cmdSourceGroupCMDBusinessUnitMapRecord.CMDSourceGroup.Id)
                                                                                                                                          .FirstOrDefault())
                                                                                          .Select(cmdSourceGroupCMDBusinessUnitMap => cmdSourceGroupCMDBusinessUnitMap).Any(cmdSourceGroupCMDBusinessUnitMap =>
                                                                                                                                                                            cmdSourceGroupCMDBusinessUnitMap.CMDBusinessUnitID == cmdPracticeSourceTrackRecord.BusinessUnitID))
                                                    .Select(cmdPracticeSourceTrackRecord => cmdPracticeSourceTrackRecord.CMDPracticeID).FirstOrDefault();
            }

            return(existingCMDPracticeIdforSameGroup);
        }
        public override void Validate()
        {
            using (var context = CMDDatabaseContext.GetContext())
            {
                if (string.IsNullOrWhiteSpace(this.Model.Email))
                {
                    var firstNameLower = Regex.Replace(this.Model.FirstName.ToLower(), @"\s+", "");
                    var lastNameLower  = Regex.Replace(this.Model.LastName.ToLower(), @"\s+", "");

                    var userName = string.Concat(firstNameLower, "-", lastNameLower);

                    var randy = new Random();

                    while (context.Users.Any(u => u.UserName == userName))
                    {
                        userName = string.Concat(firstNameLower, "-", lastNameLower, randy.Next(100, 999999));
                    }

                    this.Model.UserName = userName;
                }
            }
        }
Example #23
0
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0, string queryParameters = null) where T : class
        {
            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            context.Configuration.LazyLoadingEnabled = false;
            List <CMDPractice> customerPracticeListResult = null;

            int stateId = Convert.ToInt32(queryParameters);

            if (stateId <= 0)
            {
                return(customerPracticeListResult as List <T>);
            }

            try
            {
                IQueryable <CMDPractice> practiceList = CreateSelectQuery(context, stateId);

                if (!string.IsNullOrEmpty(whereCondition))
                {
                    practiceList = practiceList.Where(whereCondition);
                }

                var countCustomer = practiceList.Count();
                take = take == 0 ? countCustomer : take;

                orderByCondition = !string.IsNullOrEmpty(orderByCondition) ? orderByCondition : "Id";
                practiceList     = practiceList.OrderBy(orderByCondition).Skip(skip).Take(take);

                customerPracticeListResult = practiceList.ToList();
                CMDLogger.LogAudit("Obtained the Practice List by State ID from CMD", ALPHAEON.CMD.Common.Constants.General.ApplicationName);
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(customerPracticeListResult as List <T>);
        }
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            User user = null;

            if (!String.IsNullOrWhiteSpace(_email))
            {
                //I dont want a user to be matched because he had a null or white space email shared with some one who shared
                //their birthdate.
                user = this.FindUserByEmailAndDob(context);
            }

            if (null == user)
            {
                user = this.FindUserByFirstAndLastAndDob(context);
            }

            if (null == user)
            {
                user = this.CreateBrandNewUser(context);
            }

            return(user as T);
        }
        public void Refresh()
        {
            lock (_lockObject)
            {
                _cache.Clear();

                using (var context = CMDDatabaseContext.GetContext())
                {
                    foreach (var applicationCollectionFilter in context.ApplicationCollectionFilters)
                    {
                        var applicationId      = applicationCollectionFilter.ApplicationId;
                        var collectionFilterId = applicationCollectionFilter.CollectionFilterId;

                        if (!_cache.ContainsKey(applicationId))
                        {
                            _cache.Add(applicationId, new HashSet <CollectionFilterValue>());
                        }

                        _cache[applicationId].Add((CollectionFilterValue)collectionFilterId);
                    }
                }
            }
        }
        public void Refresh()
        {
            lock (_lockObject)
            {
                _cache.Clear();

                using (var context = CMDDatabaseContext.GetContext())
                {
                    foreach (var applicationCrudHook in context.ApplicationCrudHooks)
                    {
                        var applicationId = applicationCrudHook.ApplicationId;
                        var crudHookId    = applicationCrudHook.CrudHookId;

                        if (!_cache.ContainsKey(applicationId))
                        {
                            _cache.Add(applicationId, new HashSet <CrudHookValue>());
                        }

                        _cache[applicationId].Add((CrudHookValue)crudHookId);
                    }
                }
            }
        }
Example #27
0
        public T Execute <T>(CMDDatabaseContext context) where T : class
        {
            var transactionLog = new CMDTransaction
            {
                CMDUserID            = _cmdUserID,
                TxDate               = CommonUtility.GetDate(_txDate),
                CMDTransactionTypeID = _cmdTxTypeID,
                Note                = _note,
                TxCompletedDate     = CommonUtility.GetDate(_txCompletedDate),
                CMDAccountID        = _cmdAccountID,
                City                = _city,
                CMDStateID          = _cmdStateID,
                CreatedDate         = _createdDate,
                UpdatedDate         = _updatedDate,
                IsActive            = _isActive,
                UpdatedBy           = _updatedBy,
                Amount              = _amount,
                AmountAfterDiscount = _amountAfterDiscount,
                CurrencyType        = _currencyType
            };

            return(context.Create(transactionLog, false) as T);
        }
        public List <T> ExecuteList <T>(CMDDatabaseContext context, string whereCondition, string orderByCondition, int skip = 0, int take = 0, string queryParameters = null) where T : class
        {
            string classAndMethodName = string.Format(ALPHAEON.CMD.Common.Constants.General.ClassAndMethodName, this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            context.Configuration.LazyLoadingEnabled = false;

            List <CMDDashboardProduct> practiceProductListResult = null;

            try
            {
                if (string.IsNullOrEmpty(queryParameters))
                {
                    return(practiceProductListResult as List <T>);
                }

                IQueryable <CMDDashboardProduct> cmdDashboardPracticeProductList = CreateSelectQuery(context, queryParameters);

                if (!string.IsNullOrEmpty(whereCondition))
                {
                    cmdDashboardPracticeProductList = cmdDashboardPracticeProductList.Where(whereCondition);
                }

                #region Order By Condition
                orderByCondition = !string.IsNullOrEmpty(orderByCondition) ? orderByCondition : "Id";
                cmdDashboardPracticeProductList = cmdDashboardPracticeProductList.OrderBy(orderByCondition).Skip(skip).Take(take);
                #endregion

                practiceProductListResult = cmdDashboardPracticeProductList.ToList();
                CMDLogger.LogAudit("Obtained the Product List by Practice ID from CMD", ALPHAEON.CMD.Common.Constants.General.ApplicationName);
            }
            catch (Exception ex)
            {
                CMDLogger.LogException(ex, ALPHAEON.CMD.Common.Constants.General.ObjectName, ALPHAEON.CMD.Common.Constants.General.ApplicationName, classAndMethodName);
            }

            return(practiceProductListResult as List <T>);
        }
Example #29
0
        /// <summary>
        /// Create select query to get the list of transctions
        /// </summary>
        /// <param name="context">Database context</param>
        /// <param name="businessUnitId">Business unit id to get the details</param>
        /// <returns>Query to get transctions</returns>
        private static IQueryable <CMDDashboardProductTransaction> CreateSelectQuery(CMDDatabaseContext context, int businessUnitId)
        {
            return(ApplicationServices.LINQQueries.CMDTransaction.GetQueryTransactionListByCMDBusinessUnitId(context, businessUnitId)
                   .Select(cmdTransaction => new CMDDashboardProductTransaction()
            {
                Id = cmdTransaction.Id,
                TxDate = cmdTransaction.TxDate,
                CMDTransactionTypeID = cmdTransaction.CMDTransactionTypeID,
                IsActive = cmdTransaction.IsActive,
                CMDTransactionTypeName = cmdTransaction.CMDTransactionType.TxType,
                CurrencyType = cmdTransaction.CurrencyType,
                BusinessUnitName = cmdTransaction.CMDAccount.CMDBusinessUnit.Name,

                TransactionSourceRecordId = context.CMDTransactionSourceTracks.Where(cmdTransactionSourceTrack => cmdTransactionSourceTrack.CMDTransactionID == cmdTransaction.Id &&
                                                                                     cmdTransactionSourceTrack.IsActive).Select(cmdTransactionSourceTrack => cmdTransactionSourceTrack.SourceRecordID).FirstOrDefault(),

                NoOfItems = context.CMDTransactionProductMaps
                            .Where(cmdTransactionProductMap => cmdTransactionProductMap.CMDTransactionID == cmdTransaction.Id &&
                                   cmdTransactionProductMap.IsActive)
                            .Select(transactionProductMap => transactionProductMap.CMDProductID).Distinct().Count(),

                TotalAmount = cmdTransaction.Amount,
            }));
        }
Example #30
0
        public override void Validate()
        {
            var emailKey = DAL.PropertyName <User>(x => x.Email);

            if (!this.Delta.ContainsKey(emailKey))
            {
                return;
            }

            var email = this.Delta[emailKey] as string;

            if (string.IsNullOrWhiteSpace(email))
            {
                return;
            }

            using (var context = CMDDatabaseContext.GetContext())
            {
                if (context.Users.Any(x => x.Email == email && x.Id != this.Model.Id))
                {
                    throw new InvalidDataException("Email address already exists in the system.");
                }
            }
        }