Пример #1
0
        public int Save(BackendUser entity)
        {
            int tot = 0;

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    MAIL_USERS_BACKEND m = new MAIL_USERS_BACKEND();
                    m = DaoSQLServerDBHelper.MapToMailUsersBackend(entity);
                    dbcontext.MAIL_USERS_BACKEND.Add(m);
                    tot = dbcontext.SaveChanges();
                }
                if (tot != 1)
                {
                    throw new ManagedException("Utente non inserito", "ERR_BU01", string.Empty, string.Empty, null);
                }
            }
            catch (Exception ex)
            {
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nell'inserimento dell'utente in Users Backend Err_bu01 Dettagli Errore: " + entity.UserName + " " + ex.Message,
                                                                "ERR_BU01", string.Empty, string.Empty, ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);

                    log.Error(err);

                    throw mEx;
                }
                else
                {
                    throw;
                }
            }
            return(tot);
        }
Пример #2
0
        public void Update(BackendUser entity)
        {
            int tot = 0;

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    MAIL_USERS_BACKEND m = dbcontext.MAIL_USERS_BACKEND.FirstOrDefault(c => c.ID_USER == entity.UserId);
                    m = DaoSQLServerDBHelper.MapToMailUsersBackend(entity, m);
                    dbcontext.MAIL_USERS_BACKEND.Attach(m);
                    dbcontext.Entry(m).State = EntityState.Modified;
                    tot = dbcontext.SaveChanges();
                }
                if (tot != 1)
                {
                    throw new ManagedException("Utente non aggiornato", "ERR_BU02", string.Empty, string.Empty, null);
                }
            }
            catch (Exception ex)
            {
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nell'aggiornamento dell'utente in Users Backend Err_bu02 Dettagli Errore: " + entity.UserName + " " + ex.Message,
                                                                "ERR_BU02", string.Empty, string.Empty, ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);

                    log.Error(err);

                    throw mEx;
                }
                else
                {
                    throw;
                }
            }
        }