Пример #1
0
        public int Add(ThisEntity entity, ref List <string> messages)
        {
            DBEntity efEntity = new DBEntity();

            using (var context = new EntityContext())
            {
                try
                {
                    //won't have ctid if encountered exception
                    efEntity.Ctid              = entity.Ctid ?? "";
                    efEntity.EntityTypedId     = entity.EntityTypedId;
                    efEntity.DocumentUpdatedAt = entity.DocumentUpdatedAt;
                    efEntity.EnvelopeId        = entity.EnvelopeId;
                    //efEntity.Message = entity.Message; //See Import.Message
                    efEntity.Payload = entity.Payload;
                    //efEntity.ResourcePublicKey = entity.ResourcePublicKey;

                    efEntity.DownloadDate         = System.DateTime.Now;
                    efEntity.IsMostRecentDownload = true;

                    //set any existing downloads for this entity to not most recent
                    ResetIsMostRecentDownload(efEntity.Ctid);

                    context.Import_Staging.Add(efEntity);

                    // submit the change to database
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        entity.Id = efEntity.Id;
                        return(efEntity.Id);
                    }
                    else
                    {
                        //?no info on error
                        messages.Add(thisClassName + "Error - the add was not successful. ");
                        string message = string.Format(thisClassName + ".Add() Failed", "Attempted to add a Import document. The process appeared to not work, but was not an exception, so we have no message, or no clue. EntityTypeId: {0}; EnvelopeId: {1}", entity.EntityTypedId, entity.EnvelopeId);
                        EmailManager.NotifyAdmin(thisClassName + ".Add() Failed", message);
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
                {
                    string message = HandleDBValidationError(dbex, thisClassName + ".Add() ", "Import");
                    messages.Add("Error - the save was not successful. " + message);
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Add(), EntityTypeId: {0}; EnvelopeId: {1}", entity.EntityTypedId, entity.EnvelopeId));
                    messages.Add("Unexpected system error. The site administration has been notified.");
                }
            }

            return(entity.Id);
        }        //
Пример #2
0
        }//

        /// <summary>
        /// Get most recent import Record for ctid
        /// </summary>
        /// <param name="ctid"></param>
        /// <returns></returns>
        public static ThisEntity GetByCtid(string ctid)
        {
            ThisEntity entity = new ThisEntity();

            if (string.IsNullOrWhiteSpace(ctid))
            {
                return(null);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> list = context.Import_Staging
                                           .Where(s => s.Ctid == ctid)
                                           .OrderByDescending(s => s.Id)
                                           .Take(1)
                                           .ToList();

                    if (list != null && list.Count > 0)
                    {
                        DBEntity dbentity = list[0];
                        entity = new ThisEntity
                        {
                            EnvelopeId           = dbentity.EnvelopeId,
                            Ctid                 = dbentity.Ctid,
                            EntityTypedId        = dbentity.EntityTypedId,
                            Payload              = dbentity.Payload,
                            IsMostRecentDownload = dbentity.IsMostRecentDownload ?? false,
                            DownloadDate         = dbentity.DownloadDate
                        };
                        if (dbentity.DocumentUpdatedAt != null)
                        {
                            entity.DocumentUpdatedAt = ( DateTime )dbentity.DocumentUpdatedAt;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetByCtid");
            }
            return(entity);
        }//