Exemplo n.º 1
0
        public static void MapFromDB(DBEntity from, ThisEntity to, bool includingProperties)
        {
            to.Id            = from.Id;
            to.RowId         = from.RowId;
            to.CostProfileId = from.CostProfileId;
            to.CostTypeId    = from.CostTypeId;

            if (from.Codes_PropertyValue != null)
            {
                to.CostTypeName   = from.Codes_PropertyValue.Title;
                to.CostTypeSchema = from.Codes_PropertyValue.SchemaName;

                to.ProfileName = from.Codes_PropertyValue.Title;

                EnumeratedItem item = new EnumeratedItem();
                item.Id       = to.CostTypeId;
                item.Value    = to.CostTypeId.ToString();
                item.Selected = true;

                item.Name       = to.CostTypeName;
                item.SchemaName = to.CostTypeSchema;
                to.DirectCostType.Items.Add(item);
            }


            //NA 3/17/2017 - Need this to fix null errors in publishing and detail page, but it isn't working: no item is selected, and it's not clear why.
            //mp 18-11-02 - COPIED this from publisher: no item, because the Fill method looks for data in Entity.Property, and the cost type id is stored on CostProfileItem ==> NOW HANDLED ABOVE

            //to.DirectCostType = EntityPropertyManager.FillEnumeration( to.RowId, CodesManager.PROPERTY_CATEGORY_CREDENTIAL_ATTAINMENT_COST );

            to.Price = from.Price == null ? 0 : ( decimal )from.Price;

            to.PaymentPattern = from.PaymentPattern;

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

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

            //properties
            if (includingProperties)
            {
                to.ApplicableAudienceType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_AUDIENCE_TYPE);

                to.ResidencyType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_RESIDENCY_TYPE);
            }
        }
        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            to.Id            = from.Id;
            to.CostProfileId = from.CostProfileId;
            if (to.CostTypeId != from.CostTypeId)
            {
                //get the profile name from the code table
                //Models.CodeItem item = CodesManager.Codes_PropertyValue_Get( from.CostTypeId );
                //to.ProfileName = item.Title;
            }
            to.CostTypeId = from.CostTypeId;

            to.Price          = from.Price;
            to.PaymentPattern = from.PaymentPattern;
        }
Exemplo n.º 3
0
        public static ThisEntity Get(int profileId, bool includingProperties)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                DBEntity item = context.Entity_CostProfileItem
                                .SingleOrDefault(s => s.Id == profileId);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity, includingProperties);
                }
                return(entity);
            }
        }        //
Exemplo n.º 4
0
        public bool Delete(int recordId, ref string statusMessage)
        {
            bool isOK = true;

            using (var context = new EntityContext())
            {
                DBEntity p = context.Entity_CostProfileItem.FirstOrDefault(s => s.Id == recordId);
                if (p != null && p.Id > 0)
                {
                    context.Entity_CostProfileItem.Remove(p);
                    int count = context.SaveChanges();
                }
                else
                {
                    statusMessage = string.Format("CostProfileItem record was not found: {0}", recordId);
                    isOK          = false;
                }
            }
            return(isOK);
        }
Exemplo n.º 5
0
        private bool Save(ThisEntity entity, int parentId, ref SaveStatus status)
        {
            bool isValid = true;

            if (parentId == 0)
            {
                status.AddError("CostProfileItemManager.Save() - Error: the parent cost profile id was not provided.");
                return(false);
            }

            int count = 0;

            DBEntity efEntity = new DBEntity();

            using (var context = new EntityContext())
            {
                if (ValidateProfile(entity, ref status) == false)
                {
                    return(false);
                }

                try
                {
                    //just in case
                    entity.CostProfileId = parentId;

                    if (entity.Id == 0)
                    {
                        //add
                        efEntity = new DBEntity();
                        MapToDB(entity, efEntity);

                        efEntity.RowId   = Guid.NewGuid();
                        efEntity.Created = efEntity.LastUpdated = DateTime.Now;
                        context.Entity_CostProfileItem.Add(efEntity);
                        count = context.SaveChanges();
                        //update profile record so doesn't get deleted
                        entity.Id    = efEntity.Id;
                        entity.RowId = efEntity.RowId;
                        if (count == 0)
                        {
                            status.AddError(string.Format(" Unable to add Cost Item for CostProfileId: {0}, CostTypeId: {1}  ", parentId, entity.CostTypeId));
                            isValid = false;
                        }
                        else
                        {
                            UpdateParts(entity, ref status);
                        }
                    }
                    else
                    {
                        context.Configuration.LazyLoadingEnabled = false;

                        efEntity = context.Entity_CostProfileItem.SingleOrDefault(s => s.Id == entity.Id);
                        if (efEntity != null && efEntity.Id > 0)
                        {
                            //update
                            MapToDB(entity, efEntity);
                            //has changed?
                            if (HasStateChanged(context))
                            {
                                efEntity.LastUpdated = System.DateTime.Now;

                                count = context.SaveChanges();
                            }
                            //always check parts
                            entity.RowId = efEntity.RowId;
                            UpdateParts(entity, ref status);
                        }
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
                {
                    string message = HandleDBValidationError(dbex, "CostProfileItemManager.Save()", string.Format("CostProfileId: 0 , CostTypeId: {1}  ", parentId, entity.CostTypeId));

                    status.AddError(message);
                    isValid = false;
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, string.Format("CostProfileItemManager.Save(), CostProfileId: 0 , CostTypeId: {1}  ", parentId, entity.CostTypeId));
                    isValid = false;
                }
            }

            return(isValid);
        }