示例#1
0
        /// <summary>
        /// Store in database PAXMSGS object
        /// </summary>
        /// <param name="db"></param>
        /// <param name="hub"></param>
        /// <returns></returns>
        public OSUSR_UUK_PAXMSGS Save(BaggageEntities db, String hub)
        {
            OSUSR_UUK_PAXMSGS obj = this.getOSUSR_UUK_PAXMSGS();

            BaggageEntities dbins = new BaggageEntities();
            try
            {

                // Just store and send to Engine queue if it's a hub message
                if (!hub.Equals(this.IDEST))
                {
                    throw new Exception("PTM TTY message not hub, destination: " + this.IDEST);
                }

                dbins.OSUSR_UUK_PAXMSGS.Add(obj);
                dbins.SaveChanges();
                return obj;
            }
            catch (DbEntityValidationException ex)
            {
                dbins.OSUSR_UUK_PAXMSGS.Remove(obj);

                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " PTMTTYTable the validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new TableException(exceptionMessage);
            }
            catch (Exception e)
            {
                dbins.OSUSR_UUK_PAXMSGS.Remove(obj);

                throw e;
            }
        }
        public OSUSR_UUK_BAGMSGS Save(BaggageEntities db)
        {
            OSUSR_UUK_BAGMSGS obj = this.getOSUSR_UUK_BAGMSGS();

            obj.TIMESTAMP = now;

            BagTMLog.LogDebug("BagTM Queue About to Write to DB message : " + this.NBAGTAG, obj);

            BaggageEntities dbins = new BaggageEntities();

            try
            {
                dbins.OSUSR_UUK_BAGMSGS.Add(obj);
                dbins.SaveChanges();
                return(obj);
            }
            catch (DbEntityValidationException ex)
            {
                dbins.OSUSR_UUK_BAGMSGS.Remove(obj);
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " BaggageTTYTable the validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new TableException(exceptionMessage);
            }
            catch (Exception e)
            {
                dbins.OSUSR_UUK_BAGMSGS.Remove(obj);

                throw e;
            }
        }