Example #1
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;
            }
        }
Example #2
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);
        }
Example #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);
            //QuantitativeValue as json
            to.FinancialAssistanceValue = from.FinancialAssistanceValueJson;
        }
Example #4
0
        /// <summary>
        /// Delete a Financial Assistance profile, and related Entity
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Delete(int Id, ref string statusMessage)
        {
            bool isValid = false;

            if (Id == 0)
            {
                statusMessage = "Error - missing an identifier for the FinancialAssistanceProfile";
                return(false);
            }
            using (var context = new EntityContext())
            {
                try
                {
                    DBEntity efEntity = context.Entity_FinancialAssistanceProfile
                                        .SingleOrDefault(s => s.Id == Id);

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        Guid rowId = efEntity.RowId;

                        context.Entity_FinancialAssistanceProfile.Remove(efEntity);
                        int count = context.SaveChanges();
                        if (count > 0)
                        {
                            isValid = true;
                            //do with trigger now
                            //new EntityManager().Delete( rowId, ref statusMessage );
                        }
                    }
                    else
                    {
                        statusMessage = "Error - delete failed, as record was not found.";
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + ".Delete()");

                    statusMessage = FormatExceptions(ex);
                    if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1)
                    {
                        statusMessage = "Error: this Financial Assistance cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this Financial Assistance can be deleted.";
                    }
                }
            }

            return(isValid);
        }
Example #5
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);
        }
Example #6
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;
            }
        }
Example #7
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);
        }