Exemple #1
0
        private questStatus read(FMSEntities dbContext, UserSessionId userSessionId, out Quest.Services.Dbio.FMS.UserSessions userSession)
        {
            // Initialize
            userSession = null;


            try
            {
                userSession = dbContext.UserSessions.Where(r => r.Id == userSessionId.Id).SingleOrDefault();
                if (userSession == null)
                {
                    return(new questStatus(Severity.Error, String.Format("ERROR: {0}.{1}: {2}",
                                                                         this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                         String.Format("Id {0} not found", userSessionId.Id))));
                }
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, " The DbEntityValidationException errors are: ", fullErrorMessage);
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     exceptionMessage)));
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
Exemple #2
0
        private questStatus update(FMSEntities dbContext, UserSession userSession)
        {
            // Initialize
            questStatus status = null;


            try
            {
                // Read the record.
                UserSessionId userSessionId = new UserSessionId(userSession.Id);
                Quest.Services.Dbio.FMS.UserSessions _userSession = null;
                status = read(dbContext, userSessionId, out _userSession);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Update the record.
                BufferMgr.TransferBuffer(userSession, _userSession);
                dbContext.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, " The DbEntityValidationException errors are: ", fullErrorMessage);
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     exceptionMessage)));
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
Exemple #3
0
        public questStatus Read(DbMgrTransaction trans, UserSessionId userSessionId, out UserSession userSession)
        {
            // Initialize
            questStatus status = null;

            userSession = null;


            // Perform read.
            using (FMSEntities dbContext = new FMSEntities())
            {
                Quest.Services.Dbio.FMS.UserSessions _userSession = null;
                status = read((FMSEntities)trans.DbContext, userSessionId, out _userSession);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                userSession = new UserSession();
                BufferMgr.TransferBuffer(_userSession, userSession);
            }
            return(new questStatus(Severity.Success));
        }
Exemple #4
0
        /*----------------------------------------------------------------------------------------------------------------------------------
        * UserSessions
        *---------------------------------------------------------------------------------------------------------------------------------*/
        private questStatus create(FMSEntities dbContext, UserSession userSession, out UserSessionId userSessionId)
        {
            // Initialize
            userSessionId = null;


            // Perform create
            try
            {
                Quest.Services.Dbio.FMS.UserSessions _userSession = new Quest.Services.Dbio.FMS.UserSessions();
                BufferMgr.TransferBuffer(userSession, _userSession);
                dbContext.UserSessions.Add(_userSession);
                dbContext.SaveChanges();
                if (_userSession.Id == 0)
                {
                    return(new questStatus(Severity.Error, "UserSession not created"));
                }
                userSessionId = new UserSessionId(_userSession.Id);
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, " The DbEntityValidationException errors are: ", fullErrorMessage);
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     exceptionMessage)));
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }