コード例 #1
0
        public bool Delete_EntityConditionManifest(Guid parentUid, int profileId, ref string statusMessage)
        {
            bool isValid = false;

            if (profileId == 0)
            {
                statusMessage = "Error - missing an identifier for the Assessment to remove";
                return(false);
            }
            //need to get Entity.Id
            Entity parent = EntityManager.GetEntity(parentUid);

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

            using (var context = new EntityContext())
            {
                EM.Entity_ConditionManifest efEntity = context.Entity_ConditionManifest
                                                       .SingleOrDefault(s => s.EntityId == parent.Id && s.ConditionManifestId == profileId);

                if (efEntity != null && efEntity.Id > 0)
                {
                    context.Entity_ConditionManifest.Remove(efEntity);
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        isValid = true;
                    }
                }
                else
                {
                    statusMessage = "Warning - the record was not found - probably because the target had been previously deleted";
                    isValid       = true;
                }
            }

            return(isValid);
        }
コード例 #2
0
        public static Entity_ConditionManifest EntityConditionManifest_Get(int parentId, int profileId)
        {
            Entity_ConditionManifest entity = new Entity_ConditionManifest();

            if (parentId < 1 || profileId < 1)
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    EM.Entity_ConditionManifest from = context.Entity_ConditionManifest
                                                       .SingleOrDefault(s => s.ConditionManifestId == profileId && s.EntityId == parentId);

                    if (from != null && from.Id > 0)
                    {
                        entity.Id = from.Id;
                        entity.ConditionManifestId = from.ConditionManifestId;
                        entity.EntityId            = from.EntityId;
                        //entity.ConditionManifest = ConditionManifestManager.GetBasic( from.ConditionManifestId );
                        entity.ProfileSummary = entity.ConditionManifest.ProfileName;

                        //entity.ConditionManifest = from.ConditionManifest;
                        if (IsValidDate(from.Created))
                        {
                            entity.Created = ( DateTime )from.Created;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".EntityConditionManifest_Get");
            }
            return(entity);
        }        //
コード例 #3
0
        /// <summary>
        /// Add an Entity_CommonCondition
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="profileId"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public int Entity_HasConditionManifest_Add(Guid parentUid,
                                                   int profileId,
                                                   ref SaveStatus status)
        {
            int id    = 0;
            int count = 0;

            if (profileId == 0)
            {
                status.AddError(string.Format("A valid ConditionManifest identifier was not provided to the {0}.Add method.", thisClassName));
                return(0);
            }

            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the parent entity was not found.");
                return(0);
            }
            using (var context = new EntityContext())
            {
                EM.Entity_ConditionManifest efEntity = new EM.Entity_ConditionManifest();
                try
                {
                    //first check for duplicates
                    efEntity = context.Entity_ConditionManifest
                               .SingleOrDefault(s => s.EntityId == parent.Id &&
                                                s.ConditionManifestId == profileId);

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        //status.AddError( string.Format( "Error - this ConditionManifest has already been added to this profile.", thisClassName ) );
                        return(0);
                    }

                    efEntity                     = new EM.Entity_ConditionManifest();
                    efEntity.EntityId            = parent.Id;
                    efEntity.ConditionManifestId = profileId;

                    efEntity.Created = System.DateTime.Now;

                    context.Entity_ConditionManifest.Add(efEntity);

                    // submit the change to database
                    count = context.SaveChanges();
                    if (count > 0)
                    {
                        id = efEntity.Id;
                        return(efEntity.Id);
                    }
                    else
                    {
                        //?no info on error
                        status.AddError("Error - the add was not successful.");
                        string message = thisClassName + string.Format(".Add Failed", "Attempted to add a ConditionManifest for a profile. The process appeared to not work, but there was no exception, so we have no message, or no clue. Parent Profile: {0}, Type: {1}, learningOppId: {2}", parentUid, parent.EntityType, profileId);
                        EmailManager.NotifyAdmin(thisClassName + ".Add Failed", message);
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
                {
                    string message = HandleDBValidationError(dbex, thisClassName + ".Add() ", "Entity_CommonCondition");
                    status.AddError("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(dbex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                }
                catch (Exception ex)
                {
                    string message = FormatExceptions(ex);
                    status.AddError("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                }
            }
            return(id);
        }