Пример #1
0
        public bool ValidateProfile(ThisEntity profile, ref List <string> messages)
        {
            bool isValid = true;
            int  count   = messages.Count;

            //check if empty
            if (string.IsNullOrWhiteSpace(profile.Name) &&
                string.IsNullOrWhiteSpace(profile.Description) &&
                string.IsNullOrWhiteSpace(profile.SubjectWebpage)
                )
            {
                messages.Add("Please provide a little more information, before attempting to save this profile");
                return(false);
            }
            //
            if (string.IsNullOrWhiteSpace(profile.Name))
            {
                messages.Add("A Profile name must be entered");
            }

            if (!IsUrlValid(profile.SubjectWebpage, ref commonStatusMessage))
            {
                messages.Add("The profile SubjectWebpage is invalid " + commonStatusMessage);
            }



            if (messages.Count > count)
            {
                isValid = false;
            }

            return(isValid);
        }
Пример #2
0
        public static void MapFromDB(DBEntity from, ThisEntity to)
        {
            to.Id                           = from.Id;
            to.RowId                        = from.RowId;
            to.ParentId                     = from.EntityId;
            to.Name                         = GetData(from.Name);
            to.SubjectWebpage               = GetData(from.SubjectWebpage);
            to.Description                  = GetData(from.Description);
            to.FinancialAssistanceType      = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_FINANCIAL_ASSISTANCE);
            to.FinancialAssistanceValueJson = from.FinancialAssistanceValue;
            if (!string.IsNullOrWhiteSpace(to.FinancialAssistanceValueJson))
            {
                to.FinancialAssistanceValue        = JsonConvert.DeserializeObject <List <QuantitativeValue> >(to.FinancialAssistanceValueJson);
                to.FinancialAssistanceValueSummary = SummarizeFinancialAssistanceValue(to.FinancialAssistanceValue);
            }
            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }

            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
        }
Пример #3
0
        }        //

        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            //want to ensure fields from create are not wiped
            if (to.Id == 0)
            {
            }


            to.Id             = from.Id;
            to.Name           = GetData(from.Name);
            to.SubjectWebpage = GetData(from.SubjectWebpage);
            to.Description    = GetData(from.Description);
        }
Пример #4
0
        /// <summary>
        /// Get all the Financial Assistances for the parent entity (ex a credential)
        /// </summary>
        /// <param name="parentUid"></param>
        /// <returns></returns>
        public static List <ThisEntity> GetAll(Guid parentUid, bool isForLinks = false)
        {
            ThisEntity        to     = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();
            Entity            parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }

            try
            {
                using (var context = new EntityContext())
                {
                    //context.Configuration.LazyLoadingEnabled = false;

                    List <EM.Entity_FinancialAssistanceProfile> results = context.Entity_FinancialAssistanceProfile
                                                                          .Where(s => s.EntityId == parent.Id)
                                                                          .OrderBy(s => s.Name)
                                                                          .ThenBy(s => s.Created)
                                                                          .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (EM.Entity_FinancialAssistanceProfile from in results)
                        {
                            to = new ThisEntity();
                            if (isForLinks)
                            {
                                to.Id             = from.Id;
                                to.RowId          = from.RowId;
                                to.ProfileName    = from.Name;
                                to.SubjectWebpage = from.SubjectWebpage;
                            }
                            else
                            {
                                MapFromDB(from, to);
                            }
                            list.Add(to);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAll (Guid parentUid)");
            }
            return(list);
        }        //
Пример #5
0
        }        //

        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            //want to ensure fields from create are not wiped
            if (to.Id == 0)
            {
            }


            to.Id             = from.Id;
            to.Name           = GetData(from.Name);
            to.SubjectWebpage = GetData(from.SubjectWebpage);
            to.Description    = GetData(from.Description);
            //QuantitativeValue as json
            to.FinancialAssistanceValue = from.FinancialAssistanceValueJson;
        }
Пример #6
0
        public static ThisEntity Get(Guid rowId)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                DBEntity item = context.Entity_FinancialAssistanceProfile
                                .FirstOrDefault(s => s.RowId == rowId);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity);
                }
            }

            return(entity);
        }
Пример #7
0
        public static void MapFromDB(DBEntity from, ThisEntity to)
        {
            to.Id                      = from.Id;
            to.RowId                   = from.RowId;
            to.ParentId                = from.EntityId;
            to.Name                    = GetData(from.Name);
            to.SubjectWebpage          = GetData(from.SubjectWebpage);
            to.Description             = GetData(from.Description);
            to.FinancialAssistanceType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_FINANCIAL_ASSISTANCE);

            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }

            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
        }
Пример #8
0
        }        //

        public static List <ThisEntity> Search(int topParentTypeId, int topParentEntityBaseId)
        {
            ThisEntity        to     = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();
            Entity            parent = EntityManager.GetEntity(topParentTypeId, topParentEntityBaseId);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }

            try
            {
                using (var context = new EntityContext())
                {
                    //context.Configuration.LazyLoadingEnabled = false;

                    List <EM.Entity_FinancialAssistanceProfile> results = context.Entity_FinancialAssistanceProfile
                                                                          .Where(s => s.EntityId == parent.Id)
                                                                          .OrderBy(s => s.Name)
                                                                          .ThenBy(s => s.Created)
                                                                          .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (EM.Entity_FinancialAssistanceProfile from in results)
                        {
                            to = new ThisEntity();
                            MapFromDB(from, to);
                            list.Add(to);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Search (topParentTypeId, topParentEntityBaseId)");
            }
            return(list);
        }        //
Пример #9
0
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            bool   isAllValid    = true;
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found for financial assistance profile.");
                return(false);
            }

            EntityPropertyManager mgr = new EntityPropertyManager();

            //first clear all properties
            mgr.DeleteAll(relatedEntity, ref status);

            if (mgr.AddProperties(entity.FinancialAssistanceType, entity.RowId, CodesManager.ENTITY_TYPE_FINANCIAL_ASST_PROFILE, CodesManager.PROPERTY_CATEGORY_FINANCIAL_ASSISTANCE, false, ref status) == false)
            {
                isAllValid = false;
            }


            return(isAllValid);
        }         //
Пример #10
0
        /// <summary>
        /// Persist FinancialAssistanceProfile
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="parentUid"></param>
        /// <param name="userId"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity, Entity parent, ref SaveStatus status)
        {
            bool isValid     = true;
            int  intialCount = messages.Count;

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(false);
            }

            if (messages.Count > intialCount)
            {
                return(false);
            }

            int count = 0;

            DBEntity efEntity = new DBEntity();

            using (var context = new EntityContext())
            {
                try
                {
                    if (ValidateProfile(entity, ref messages) == false)
                    {
                        return(false);
                    }
                    bool doingParts = true;
                    if (entity.Id == 0)
                    {
                        //add
                        efEntity = new DBEntity();
                        MapToDB(entity, efEntity);
                        efEntity.EntityId = parent.Id;
                        efEntity.Created  = efEntity.LastUpdated = DateTime.Now;
                        efEntity.RowId    = Guid.NewGuid();

                        context.Entity_FinancialAssistanceProfile.Add(efEntity);
                        count = context.SaveChanges();

                        entity.Id    = efEntity.Id;
                        entity.RowId = efEntity.RowId;
                        if (count == 0)
                        {
                            messages.Add(" Unable to add Financial Assistance Profile");
                            doingParts = false;
                        }
                    }
                    else
                    {
                        efEntity = context.Entity_FinancialAssistanceProfile.SingleOrDefault(s => s.Id == entity.Id);
                        if (efEntity != null && efEntity.Id > 0)
                        {
                            entity.RowId = efEntity.RowId;
                            //update
                            MapToDB(entity, efEntity);
                            //has changed?
                            if (HasStateChanged(context))
                            {
                                efEntity.LastUpdated = System.DateTime.Now;
                                count = context.SaveChanges();
                            }
                        }
                    }
                    //ALWAYS DO PARTS
                    if (doingParts)
                    {
                        UpdateParts(entity, ref status);
                    }
                }
                catch (Exception ex)
                {
                    string message = FormatExceptions(ex);
                    messages.Add("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                    isValid = false;
                }
            }

            return(isValid);
        }