Ejemplo n.º 1
0
        /// <param name="dr">datarecord</param>
        /// <remarks>RIVEDERE</remarks>
        /// <summary>
        /// Mappa un record su di un oggetto BackendUser.
        /// </summary>/// <returns></returns>
        internal static BackendUser MapToBackendUser(IDataRecord dr)
        {
            BackendUser bUser = new BackendUser();

            bUser.UserId     = (long)dr.GetValue("ID_USER");
            bUser.UserName   = dr.GetValue("USER_NAME").ToString();
            bUser.Department = dr.GetInt64("DEPARTMENT");

            if (dr.GetValue("MUNICIPIO") != null)
            {
                bUser.Municipio = dr.GetValue("MUNICIPIO").ToString();
            }
            else
            {
                bUser.Municipio = string.Empty;
            }

            bUser.Domain   = dr.GetValue("DOMAIN").ToString();
            bUser.Cognome  = dr.GetValue("COGNOME").ToString();
            bUser.Nome     = dr.GetValue("NOME").ToString();
            bUser.UserRole = int.Parse(dr.GetValue("ROLE_USER").ToString());
            if (dr.GetValue("ROLE_MAIL") != null)
            {
                bUser.RoleMail = int.Parse(dr.GetValue("ROLE_MAIL").ToString());
            }

            return(bUser);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Промена на Администратор во Институција во неактивен
        /// </summary>
        /// <returns></returns>
        protected override ActionResult Delete()
        {
            try
            {
                using (var scope = new UnitOfWorkScope())
                {
                    BackendUser currentUser = _backendUserRepository.Get(Convert.ToInt32(GridModel.Id));

                    var user = _userRepository.GetUserByUsername(GridModel.UserName);
                    if (user != null && currentUser.Id != user.Id)
                    {
                        throw new DuplicateKeyException();
                    }

                    currentUser.IsActive = false;

                    _backendUserRepository.Update(currentUser);
                    scope.Commit();
                }

                return(Json(GridModel));
            }
            catch (DuplicateKeyException)
            {
                ModelState.AddModelError(string.Empty, string.Format("User with username {0} already exists in the system.", GridModel.UserName));
            }
            throw CreateModelException(GridModel);
        }
Ejemplo n.º 3
0
 public void Update(BackendUser userBackend)
 {
     using (BackEndUserSQLDb dao = new BackEndUserSQLDb())
     {
         dao.Update(userBackend);
     }
 }
Ejemplo n.º 4
0
 public int Save(BackendUser entity)
 {
     using (BackEndUserSQLDb dao = new BackEndUserSQLDb())
     {
         return(dao.Save(entity));
     }
 }
Ejemplo n.º 5
0
        public BackendUser GetByUserName(String UserName)
        {
            BackendUser backendUser = null;

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    MAIL_USERS_BACKEND d = dbcontext.MAIL_USERS_BACKEND.Where(x => x.USER_NAME.ToUpper() == UserName.ToUpper()).First();
                    backendUser = AutoMapperConfiguration.FromMailUsersBackendToModel(d);
                    if (backendUser != null && backendUser.UserId >= 0)
                    {
                        var musb = dbcontext.MAIL_USERS_SENDER_BACKEND.Where(x => x.REF_ID_USER == d.ID_USER).ToList();
                        backendUser.MappedMails = (List <BackEndUserMailUserMapping>) this.GetMailUserByUserId(backendUser.UserId, backendUser.UserRole);
                    }
                }
            }
            catch (Exception e)
            {
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione del profilo utente abilitati per username : "******" E078 Dettagli Errore: " + e.Message,
                                                                "ERR_078", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                }
                backendUser = null;
            }

            return(backendUser);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Mappa un record su di un oggetto Nominativo in Rubrica.
        /// </summary>
        /// <param name="dr">datarecord</param>
        /// <returns></returns>
        //internal static Nominativo MapToNominativoRubrica(IDataRecord dr)
        //{
        //    return MapToNominativo(dr, "ID_CONTACT");
        //}
        /// <param name="dr">datarecord</param>
        /// <remarks>RIVEDERE</remarks>
        /// <summary>
        /// Mappa un Dipartimento su di un oggetto BackendUser.
        /// </summary>/// <returns></returns>
        internal static BackendUser MapToDepartment(IDataRecord dr)
        {
            BackendUser bUser = new BackendUser();

            bUser.Department = dr.GetInt64("DEPARTMENT");
            return(bUser);
        }
Ejemplo n.º 7
0
        public ICollection <BackendUser> GetAll()
        {
            List <BackendUser> listaUtenti = new List <BackendUser>();

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    using (var oCmd = dbcontext.Database.Connection.CreateCommand())
                    {
                        oCmd.CommandText = "SELECT MAIL_USERS_BACKEND.ID_USER, " +
                                           "MAIL_USERS_BACKEND.USER_NAME, " +
                                           "MAIL_USERS_BACKEND.COGNOME, " +
                                           "MAIL_USERS_BACKEND.NOME, " +
                                           "MAIL_USERS_BACKEND.DEPARTMENT, " +
                                           "MAIL_USERS_BACKEND.MUNICIPIO, " +
                                           "MAIL_USERS_BACKEND.DOMAIN, " +
                                           "MAIL_USERS_BACKEND.ROLE ROLE_USER " +
                                           "FROM  [FAXPEC].[FAXPEC].[MAIL_USERS_BACKEND] ";
                        oCmd.Connection.Open();
                        using (var r = oCmd.ExecuteReader())
                        {
                            if (r.HasRows)
                            {
                                listaUtenti = new List <BackendUser>();
                                while (r.Read())
                                {
                                    BackendUser bUser = AutoMapperConfiguration.MapToBackendUser(r);
                                    if (bUser != null && bUser.UserId >= 0)
                                    {
                                        BackEndUserMailUserMapping b = new BackEndUserMailUserMapping();
                                        b.MailSenderId    = 0;
                                        b.MailAccessLevel = 0;
                                        List <BackEndUserMailUserMapping> bList = new List <BackEndUserMailUserMapping>();
                                        bList.Add(b);
                                        bUser.MappedMails = bList;
                                    }
                                    listaUtenti.Add(bUser);
                                }
                            }
                        }
                        oCmd.Connection.Close();
                    }
                }
            }
            catch (Exception e)
            {
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione lista utenti generale E172 Dettagli Errore: " + e.Message,
                                                                "ERR_172", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                }
                listaUtenti = null;
            }

            return(listaUtenti);
        }
Ejemplo n.º 8
0
 internal static MAIL_USERS_BACKEND MapToMailUsersBackend(BackendUser u, MAIL_USERS_BACKEND b)
 {
     b.CODICE_FISCALE = u.CodiceFiscale;
     b.COGNOME        = u.Cognome;
     b.DEPARTMENT     = u.Department;
     b.DOMAIN         = u.Domain;
     b.NOME           = u.Nome;
     return(b);
 }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (MySecurityProvider.CurrentPrincipal == null)
            {
                Redirect("LogOffPage", null);
                //Response.Redirect("~/LogOff.aspx");
            }

            try
            {
                if (!(SessionManager <BackendUser> .exist(SessionKeys.BACKEND_USER)))
                {
                    BackendUserService buservice = new BackendUserService();
                    _bUser = (BackendUser)buservice.GetByUserName(MySecurityProvider.CurrentPrincipal.MyIdentity.UserName);
                    SessionManager <BackendUser> .set(SessionKeys.BACKEND_USER, _bUser);
                }
                else
                {
                    _bUser = SessionManager <BackendUser> .get(SessionKeys.BACKEND_USER);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException("Errore nel caricamento dei dati utente", "CM001",
                                                                string.Empty, string.Empty, ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.loggingAppCode = "WEB_MAIL";
                    err.objectID       = this.Context.Session.SessionID;
                    log.Error(err);
                    info.AddMessage(ex.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                }
                else
                {
                    info.AddMessage(ex.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                }
            }

            if (!IsPostBack)
            {
                if (bUser != null)
                {
                    this.UserIdBackendUser_ViewState = bUser.UserId;
                    if (bUser.UserRole != 2)
                    {
                        this.Dipartimento_ViewState = MySecurityProvider.CurrentPrincipal.MyIdentity.dipartimento;
                    }
                    popolaGridElencoEmailsShared();
                }
                else
                {
                    //Response.Redirect("~/LogOff.aspx");
                    Redirect("LogOffPage", null);
                }
            }
        }
Ejemplo n.º 10
0
 protected void lvUtentiAdmin_ItemDataBound(object sender, ListViewItemEventArgs e)
 {
     if (e.Item.ItemType == ListViewItemType.DataItem)
     {
         ListViewDataItem dataItem = (ListViewDataItem)e.Item;
         BackendUser      bUser    = (BackendUser)dataItem.DataItem;
         (e.Item.FindControl("lb_ROLE_ADMIN") as HiddenField).Value = bUser.MappedMails[0].MailAccessLevel.ToString();
     }
 }
Ejemplo n.º 11
0
        public BackendUser GetByUserName(String UserName)
        {
            BackendUser backendUser = null;

            try
            {
                using (OracleCommand oCmd = base.CurrentConnection.CreateCommand())
                {
                    oCmd.CommandText = "SELECT MAIL_USERS_BACKEND.ID_USER, " +
                                       "MAIL_USERS_BACKEND.USER_NAME, " +
                                       "MAIL_USERS_BACKEND.DEPARTMENT, " +
                                       "MAIL_USERS_BACKEND.MUNICIPIO, " +
                                       "MAIL_USERS_BACKEND.DOMAIN, " +
                                       "MAIL_USERS_BACKEND.COGNOME, " +
                                       "MAIL_USERS_BACKEND.NOME, " +
                                       "MAIL_USERS_BACKEND.ROLE ROLE_USER, " +
                                       " '' AS ROLE_MAIL " +
                                       "FROM MAIL_USERS_BACKEND WHERE UPPER(USER_NAME) = :USER_NAME";

                    oCmd.Parameters.Add("USER_NAME", UserName.ToUpper());
                    using (OracleDataReader r = oCmd.ExecuteReader())
                    {
                        while (r.Read())
                        {
                            backendUser = DaoOracleDbHelper.MapToBackendUser(r);
                        }
                    }
                }

                if (backendUser != null && backendUser.UserId >= 0)
                {
                    backendUser.MappedMails = (List <BackEndUserMailUserMapping>) this.GetMailUserByUserId(backendUser.UserId, backendUser.UserRole);
                }
            }
            catch (Exception e)
            {
                //TASK: Allineamento log - Ciro
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione del profilo utente abilitati per username : "******" E078 Dettagli Errore: " + e.Message,
                                                                "ERR_078", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                }
                //Com.Delta.Logging.Errors.ErrorLogInfo error = new Com.Delta.Logging.Errors.ErrorLogInfo();
                //error.freeTextDetails = "Errore nella creazione del profilo utente abilitati per username : "******" E078 Dettagli Errore: " + e.Message;
                //error.logCode = "ERR_078";
                //error.passiveparentcodeobjectID = string.Empty;
                //error.passiveobjectGroupID = UserName.ToString();
                //error.passiveobjectID = string.Empty;
                //error.passiveapplicationID = string.Empty;
                //log.Error(error);
                backendUser = null;
            }

            return(backendUser);
        }
Ejemplo n.º 12
0
        protected void odsMailConfig_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            MailUser           mu = e.InputParameters[0] as MailUser;
            MailAccountService mailAccountService = new MailAccountService();

            mu.IdResponsabile = decimal.Parse(MySecurityProvider.CurrentPrincipal.MyIdentity.Id);
            if (!IsValidEmailDesc(mu.EmailAddress))
            {
                e.Cancel = true;
                info.AddMessage("Errore nel formato della mail", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                return;
            }
            try
            {
                mu.FlgManaged = (mu.FlgManagedInsert == true) ? 1 : 0;
                string serverId = (fvEmail.FindControl("ddlListaServers") as DropDownList).SelectedValue;
                int    serverid = 0;
                int.TryParse(serverId, out serverid);
                if (mailAccountService.GetUserByServerAndUsername(serverid, mu.EmailAddress.ToLower()).FirstOrDefault().Id > 0)
                {
                    info.AddMessage("Attenzione email già esistente", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                    e.Cancel = true;
                    return;
                }
                else
                {
                    mailAccountService.Insert(mu);
                    this.IdSender_ViewState = mu.UserId;
                    BackendUserService buservice = new BackendUserService();
                    _bUser = (BackendUser)buservice.GetByUserName(MySecurityProvider.CurrentPrincipal.MyIdentity.UserName);
                    popolaGridElencoEmailsShared();
                    SessionManager <BackendUser> .set(SessionKeys.BACKEND_USER, _bUser);

                    info.AddMessage("Operazione effettuata", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.OK);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException("Errore nell'inserimento della nuova configurazione mail", "CM009",
                                                                string.Empty, string.Empty, ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.loggingAppCode = "WEB_MAIL";
                    err.objectID       = this.Context.Session.SessionID;
                    log.Error(err);

                    info.AddMessage(mEx.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                }
                else
                {
                    info.AddMessage(ex.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                }
            }
            e.Cancel = true;
        }
Ejemplo n.º 13
0
        public List <BackendUser> GetDipendentiDipartimentoNONAbilitati(String dipartimento, Decimal idSender)
        {
            List <BackendUser> listaDipendenti = null;

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    using (var oCmd = dbcontext.Database.Connection.CreateCommand())
                    {
                        oCmd.CommandText = "SELECT DISTINCT MAIL_USERS_BACKEND.ID_USER, " +
                                           "MAIL_USERS_BACKEND.USER_NAME, " +
                                           "MAIL_USERS_BACKEND.COGNOME, " +
                                           "MAIL_USERS_BACKEND.NOME, " +
                                           "MAIL_USERS_BACKEND.DEPARTMENT, " +
                                           "MAIL_USERS_BACKEND.MUNICIPIO, " +
                                           "MAIL_USERS_BACKEND.DOMAIN, " +
                                           "0 as  ROLE_USER, " +
                                           "0 AS ROLE_MAIL" +
                                           " FROM  [FAXPEC].[FAXPEC].[MAIL_USERS_BACKEND] " +
                                           " LEFT OUTER JOIN  [FAXPEC].[FAXPEC].[MAIL_USERS_SENDER_BACKEND] ON ID_USER=REF_ID_USER " +
                                           " WHERE MAIL_USERS_BACKEND.ID_USER NOT IN " +
                                           " (SELECT MAIL_USERS_SENDER_BACKEND.REF_ID_USER FROM  [FAXPEC].[FAXPEC].[MAIL_USERS_SENDER_BACKEND] " +
                                           "WHERE MAIL_USERS_SENDER_BACKEND.REF_ID_SENDER = " + idSender + ") " +
                                           "AND MAIL_USERS_BACKEND.DEPARTMENT = '" + dipartimento + "'";
                        using (var r = oCmd.ExecuteReader())
                        {
                            if (r.HasRows)
                            {
                                listaDipendenti = new List <BackendUser>();
                                while (r.Read())
                                {
                                    BackendUser bUser = AutoMapperConfiguration.MapToBackendUser(r);
                                    listaDipendenti.Add(bUser);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione lista utenti non abilitati per email e dipartimento : " + idSender.ToString() + " " + dipartimento + " E074 Dettagli Errore: " + e.Message,
                                                                "ERR_074", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);

                    log.Error(err);
                }
                listaDipendenti = null;
            }

            return(listaDipendenti);
        }
Ejemplo n.º 14
0
 private async void Logout()
 {
     try
     {
         // Prepare the User backend object.
         BackendUser backend = new BackendUser();
         await backend.Logout();
     }
     catch (System.Net.WebException ex)
     {
         System.Diagnostics.Debug.WriteLine("Encountered an error while trying to connect to the server: " + ex.Message);
     }
 }
Ejemplo n.º 15
0
        internal static MAIL_USERS_BACKEND MapToMailUsersBackend(BackendUser u)
        {
            MAIL_USERS_BACKEND m = new MAIL_USERS_BACKEND()
            {
                USER_NAME      = u.UserName,
                ID_USER        = u.UserId,
                COGNOME        = u.Cognome,
                DEPARTMENT     = u.Department,
                ROLE           = u.RoleMail.ToString(),
                NOME           = u.Nome,
                CODICE_FISCALE = u.CodiceFiscale,
                DOMAIN         = u.Domain
            };

            return(m);
        }
Ejemplo n.º 16
0
        protected void odsMailConfig_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            MailUser           mu = e.InputParameters[0] as MailUser;
            MailAccountService mailAccountService = new MailAccountService();

            if (!IsValidEmailDesc(mu.EmailAddress))
            {
                e.Cancel = true;
                info.AddMessage("Errore nel formato della mail", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                return;
            }
            try
            {
                mailAccountService.Insert(mu);
                this.IdSender_ViewState = mu.UserId;
                BackendUserService buservice = new BackendUserService();
                _bUser = (BackendUser)buservice.GetByUserName(MySecurityProvider.CurrentPrincipal.MyIdentity.UserName);
                popolaGridElencoEmailsShared();
                info.AddMessage("Operazione effettuata", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.OK);
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException("Errore nell'inserimento della nuova configurazione mail", "CM009",
                                                                string.Empty, string.Empty, ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.loggingAppCode = "WEB_MAIL";
                    err.objectID       = this.Context.Session.SessionID;
                    log.Error(err);

                    info.AddMessage(mEx.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                }
                else
                {
                    info.AddMessage(ex.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR);
                }
            }
            e.Cancel = true;
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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;
                }
            }
        }
        private async void Register_OnClick(object sender, EventArgs e)
        {
            // Collect all of the data from the UI.
            string firstname = View.FindViewById <EditText>(Resource.Id.etFirstName).Text;
            string lastname  = View.FindViewById <EditText>(Resource.Id.etLastName).Text;
            string username  = View.FindViewById <EditText>(Resource.Id.etUsername).Text;
            string password  = View.FindViewById <EditText>(Resource.Id.etPassword).Text;

            if (firstname == "" || lastname == "" || username == "" || password == "")
            {
                // At least one field is empty.
                View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.register_required_fields);
                return;
            }

            try
            {
                // Create an instance of the backend and register the user.
                BackendUser backend = new BackendUser();
                await backend.Register(firstname, lastname, username, password);

                // Switch back to the login activity
                Fragment fragment = new LoginFragment();

                // Load the fragment.
                FragmentManager.BeginTransaction()
                .Replace(Resource.Id.content, fragment)
                .Commit();
            }
            catch (WebException ex)
            {
                // Use WebException to get the status code returned from the API.
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Forbidden)
                {
                    // One of the fields is empty.
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.register_required_fields);
                }
                else if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Conflict)
                {
                    // Username is taken.
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.register_username_taken);
                }
                else
                {
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.unknown_error);
                }
            }
            catch (BackendTimeoutException)
            {
                // Display a popup.
                DisplayAlert(GetString(Resource.String.timeout), GetString(Resource.String.timeout_message));
            }
            catch (AggregateException ex)
            {
                // Catch the aggregate exception, this might be thrown by the asynchronous tasks in the backend.
                // Handle any of the types that we are aware of.
                // Managing of aggregate exceptions modified from code found here: https://msdn.microsoft.com/en-us/library/dd537614%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

                ex.Handle((x) =>
                {
                    if (x is WebException)
                    {
                        // Check for an inner exception of Socket Exception
                        if (x.InnerException is System.Net.Sockets.SocketException)
                        {
                            // There is an issue connecting to the backend.
                            DisplayAlert(GetString(Resource.String.connection_failed), GetString(Resource.String.connection_failed_message));
                        }

                        // This exception matched, return true.
                        return(true);
                    }

                    // Was not able to handle the exception.
                    return(false);
                });
            }
        }
Ejemplo n.º 20
0
        public HttpResponseMessage RegisterUser(FormDataCollection formsValues)
        {
            var        userStore     = new UserStore();
            UsersModel model         = new UsersModel();
            var        userName      = formsValues["UserName"];
            var        password      = formsValues["Password"];
            var        cognome       = formsValues["Cognome"];
            var        nome          = formsValues["Nome"];
            var        role          = formsValues["Role"];
            var        codicefiscale = formsValues["CodiceFiscale"];
            var        user          = new IdentityUser()
            {
                UserName = userName.ToUpper()
            };

            user.PasswordHash  = MySecurityProvider.PlainToSHA256(password);
            user.SecurityStamp = System.DateTime.Now.Ticks.ToString();
            try
            {
                string result = userStore.CreateAsync(user).Result;
                user.Id = userStore.FindByNameAsync(userName.ToUpper()).Result.Id;
                if (result == "OK")
                {
                    BackendUserService bus         = new BackendUserService();
                    BackendUser        userBackend = new BackendUser();
                    userBackend.Cognome       = cognome.Trim().ToUpper();
                    userBackend.Nome          = nome.Trim().ToUpper();
                    userBackend.UserName      = userName.Trim().ToUpper();
                    userBackend.CodiceFiscale = codicefiscale.Trim().ToUpper();
                    userBackend.Domain        = role.ToUpper();
                    userBackend.UserId        = long.Parse(user.Id);
                    bus.Save(userBackend);
                    model.success = "true";
                }
                else
                {
                    model.success = "false";
                    model.message = "Utente non creato";
                }
                var resultRole = (userStore.AddToRoleAsync(user, int.Parse(role.ToUpper()))).Result;
                if (resultRole != 1)
                {
                    model.success = "false";
                    model.message = string.Format("Utente {0} non aggiunto a ruolo {1} è stato correttamente creato!", user.UserName, role);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException("Errore creazione utente. Dettaglio: " + ex.Message +
                                                                "StackTrace: " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : " vuoto "),
                                                                "ERR317",
                                                                string.Empty,
                                                                string.Empty,
                                                                ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                    model.success = "false";
                    model.message = string.Format("Utente {0} non correttamente creato", user.UserName);
                }
                else
                {
                    model.success = "false";
                    model.message = "Utene non creato";
                }
                return(this.Request.CreateResponse <UsersModel>(HttpStatusCode.OK, model));
            }
            return(this.Request.CreateResponse <UsersModel>(HttpStatusCode.OK, model));
        }
Ejemplo n.º 21
0
        private async void Login_OnClick(object sender, EventArgs e)
        {
            // Get the TextView's the contain the username and password.
            TextView usernameTxt = View.FindViewById <TextView>(Resource.Id.txtUsername);
            TextView passwordTxt = View.FindViewById <TextView>(Resource.Id.txtPassword);

            // Extract the text.
            string username = usernameTxt.Text.Trim();
            string password = passwordTxt.Text.Trim();

            if (username == "" || password == "")
            {
                View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.login_required_fields);
                return;
            }

            // Use a try and catch to determine if the username or password is incorrect.
            try
            {
                // Create an instance of the backend.
                BackendUser backend = new BackendUser();
                await backend.Login(username, password);

                // Switch back to the Planner fragment
                Fragment fragment = new PlannerDailyFragment();

                // Load the fragment.
                FragmentManager.BeginTransaction()
                .Replace(Resource.Id.content, fragment)
                .Commit();
            }
            catch (WebException ex)
            {
                // Use WebException to get the status code returned from the API.
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized)
                {
                    // User failed to authenticate. Tell them the username or password is incorrect.
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.login_incorrect);
                }
                else
                {
                    // Some other error was thrown.
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.unknown_error);
                }
            }
            catch (BackendTimeoutException)
            {
                // Display a popup.
                DisplayAlert(GetString(Resource.String.timeout), GetString(Resource.String.timeout_message));
            }
            catch (AggregateException ex)
            {
                // Catch the aggregate exception, this might be thrown by the asynchronous tasks in the backend.
                // Handle any of the types that we are aware of.
                // Managing of aggregate exceptions modified from code found here: https://msdn.microsoft.com/en-us/library/dd537614%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

                ex.Handle((x) =>
                {
                    if (x is WebException)
                    {
                        // Check for an inner exception of Socket Exception
                        if (x.InnerException is System.Net.Sockets.SocketException)
                        {
                            // There is an issue connecting to the backend.
                            DisplayAlert(GetString(Resource.String.connection_failed), GetString(Resource.String.connection_failed_message));
                        }

                        // This exception matched, return true.
                        return(true);
                    }

                    // Was not able to handle the exception.
                    return(false);
                });
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Промена на податоците за Администратор
        /// </summary>
        /// <returns></returns>
        protected override ActionResult Update()
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var scope = new UnitOfWorkScope())
                    {
                        BackendUser currentUser = _backendUserRepository.Get(Convert.ToInt32(GridModel.Id));
                        var         user        = _userRepository.GetUserByUsername(GridModel.UserName);
                        //if (user != null && currentUser.Id != user.Id)
                        //{
                        //    throw new DuplicateKeyException();
                        //}

                        //set the language
                        var lang = _langRepository.Get(GridModel.PreferedLanguage);
                        currentUser.SetPreferedLanguage(lang);

                        //set the institution
                        Institution institution = _institutionRepository.Get(GridModel.InstitutionId);

                        if (institution.InstitutionType == InstitutionType.Ministry || institution.InstitutionType == InstitutionType.Municipality ||
                            institution.InstitutionType == InstitutionType.GradSkopje || institution.InstitutionType == InstitutionType.Dtirz)
                        {
                            var  role    = _roleRepository.GetRoleByName(currentUser.Roles.Select(x => x.RoleName).FirstOrDefault());
                            Role roleNew = _roleRepository.GetRoleByName(Roles.MunicipalityAdministrator);
                            if (roleNew.RoleName != role.RoleName)
                            {
                                currentUser.Roles.RemoveAll();
                                currentUser.AddToRole(roleNew);
                            }

                            currentUser.SetInstitution(institution);
                        }
                        else
                        {
                            var role = _roleRepository.GetRoleByName(currentUser.Roles.Select(x => x.RoleName).FirstOrDefault());

                            Role roleNew;
                            if (institution.Tag == "UPRAVENINSPEKTORAT")
                            {
                                roleNew = _roleRepository.GetRoleByName(Roles.UpravenInspektor);
                            }
                            else
                            {
                                roleNew = _roleRepository.GetRoleByName(Roles.ExternalUsers);
                            }

                            if (roleNew.RoleName != role.RoleName)
                            {
                                currentUser.Roles.RemoveAll();
                                currentUser.AddToRole(roleNew);
                            }

                            currentUser.SetInstitution(institution);
                        }


                        //set props
                        currentUser.SetUserName(GridModel.UserName);
                        currentUser.SetFirstName(GridModel.FirstName);
                        currentUser.SetLastName(GridModel.LastName);
                        currentUser.IsActive = GridModel.IsActive;

                        _backendUserRepository.Update(currentUser);
                        scope.Commit();
                    }

                    return(Json(GridModel));
                }
            }
            catch (DuplicateKeyException)
            {
                ModelState.AddModelError(string.Empty, string.Format("Корисникот со корисничко име {0} веќе постои во системот.", GridModel.UserName));
            }

            throw CreateModelException(GridModel);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Додава нов Администратор во Институција
        /// </summary>
        /// <returns></returns>
        protected override ActionResult Add()
        {
            try
            {
                if (ModelState.IsValid)
                {
                    User newUser;
                    //SendWelcomeEmailToUserViewModel sendWelcomeEmailToUserViewModel;
                    using (var scope = new UnitOfWorkScope())
                    {
                        var user = _userRepository.GetUserByUsername(GridModel.UserName);
                        if (user != null)
                        {
                            throw new DuplicateKeyException();
                        }

                        //Generate the Password
                        string password    = new PasswordGenerator().Generate();
                        string passwordEnc = password.Md5String();

                        //Get the Institution
                        Institution institution = _institutionRepository.Get(GridModel.InstitutionId);

                        //Create new User
                        var lang = _langRepository.Get(GridModel.PreferedLanguage);
                        newUser = new BackendUser(GridModel.UserName, passwordEnc, GridModel.FirstName, GridModel.LastName, lang, institution)
                        {
                            IsActive = GridModel.IsActive
                        };

                        if (institution.InstitutionType == InstitutionType.Ministry || institution.InstitutionType == InstitutionType.Municipality ||
                            institution.InstitutionType == InstitutionType.GradSkopje || institution.InstitutionType == InstitutionType.Dtirz)
                        {
                            //Add to Administrator By Default
                            var role = _roleRepository.GetRoleByName(Roles.MunicipalityAdministrator);
                            newUser.AddToRole(role);
                        }
                        else
                        {
                            if (institution.Tag == "UPRAVENINSPEKTORAT")
                            {
                                var role = _roleRepository.GetRoleByName(Roles.UpravenInspektor);
                                newUser.AddToRole(role);
                            }
                            else
                            {
                                //Add to Exteral Institutions Users
                                var role = _roleRepository.GetRoleByName(Roles.ExternalUsers);
                                newUser.AddToRole(role);
                            }
                        }

                        //sendWelcomeEmailToUserViewModel = new SendWelcomeEmailToUserViewModel
                        //{
                        //    FullName = newUser.FullName,
                        //    Password = password
                        //};

                        //Save It
                        _backendUserRepository.Save(newUser);
                        scope.Commit();
                    }

                    //Send Welcome email to created administrator
                    //sendWelcomeEmailToUserViewModel.To = newUser.UserName;
                    //MailService.SendWelcomeEmailToUser(sendWelcomeEmailToUserViewModel);

                    return(Json(GridModel));
                }
            }
            catch (DuplicateKeyException)
            {
                ModelState.AddModelError(string.Empty, string.Format("Корисникот со корисничко име {0} веќе постои во системот.", GridModel.UserName));
            }
            throw CreateModelException(GridModel);
        }
Ejemplo n.º 24
0
 public int Save(BackendUser entity)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
 public void Update(BackendUser entity)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 26
0
        public List <BackendUser> GetDipendentiDipartimentoAbilitati(Decimal idSender)
        {
            List <BackendUser> listaDipendenti = null;

            try
            {
                using (OracleCommand oCmd = base.CurrentConnection.CreateCommand())
                {
                    oCmd.CommandText = "SELECT MAIL_USERS_BACKEND.ID_USER, " +
                                       "MAIL_USERS_BACKEND.USER_NAME, " +
                                       "MAIL_USERS_BACKEND.COGNOME, " +
                                       "MAIL_USERS_BACKEND.NOME, " +
                                       "MAIL_USERS_BACKEND.DEPARTMENT, " +
                                       "MAIL_USERS_BACKEND.MUNICIPIO, " +
                                       "MAIL_USERS_BACKEND.DOMAIN, " +
                                       "MAIL_USERS_BACKEND.ROLE ROLE_USER, " +
                                       "MAIL_USERS_SENDER_BACKEND.REF_ID_SENDER ID_SENDER, " +
                                       "MAIL_USERS_SENDER_BACKEND.ROLE AS ROLE_MAIL " +
                                       "FROM MAIL_USERS_BACKEND, MAIL_USERS_SENDER_BACKEND " +
                                       "WHERE MAIL_USERS_BACKEND.ID_USER = MAIL_USERS_SENDER_BACKEND.REF_ID_USER " +
                                       "AND MAIL_USERS_SENDER_BACKEND.REF_ID_SENDER = :ID_SENDER " +
                                       "ORDER BY MAIL_USERS_SENDER_BACKEND.DATA_INSERIMENTO DESC";

                    oCmd.Parameters.Add("ID_SENDER", idSender);
                    using (OracleDataReader r = oCmd.ExecuteReader())
                    {
                        if (r.HasRows)
                        {
                            listaDipendenti = new List <BackendUser>();
                            while (r.Read())
                            {
                                BackendUser bUser = DaoOracleDbHelper.MapToBackendUser(r);

                                if (bUser != null && bUser.UserId >= 0)
                                {
                                    BackEndUserMailUserMapping        b     = DaoOracleDbHelper.MapToBackEndUserMailUserMapping(r);
                                    List <BackEndUserMailUserMapping> bList = new List <BackEndUserMailUserMapping>();
                                    bList.Add(b);
                                    bUser.MappedMails = bList;
                                }
                                listaDipendenti.Add(bUser);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //TASK: Allineamento log - Ciro
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione lista utenti abilitati per email: " + idSender.ToString() + " E072 Dettagli Errore: " + e.Message,
                                                                "ERR_072", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                }
                //Com.Delta.Logging.Errors.ErrorLogInfo error = new Com.Delta.Logging.Errors.ErrorLogInfo();
                //error.freeTextDetails = "Errore nella creazione lista utenti abilitati per email: " + idSender.ToString() + " E072 Dettagli Errore: " + e.Message;
                //error.logCode = "ERR_072";
                //error.passiveparentcodeobjectID = string.Empty;
                //error.passiveobjectGroupID = idSender.ToString();
                //error.passiveobjectID = string.Empty;
                //error.passiveapplicationID = string.Empty;
                //log.Error(error);
                listaDipendenti = null;
            }

            return(listaDipendenti);
        }
Ejemplo n.º 27
0
        public HttpResponseMessage UpdateOwnProfile(FormDataCollection formsValues)
        {
            UsersMailModel model         = new UsersMailModel();
            var            userName      = formsValues["UserName"];
            var            password      = formsValues["Password"];
            var            cognome       = formsValues["Cognome"];
            var            nome          = formsValues["Nome"];
            var            domain        = formsValues["Domain"];
            var            codicefiscale = formsValues["CodiceFiscale"];
            var            userStore     = new UserStore();
            string         result        = "OK";

            try
            {
                var user = userStore.FindByNameAsync(userName).Result;
                if (!(string.IsNullOrEmpty(password)))
                {
                    user.PasswordHash  = MySecurityProvider.PlainToSHA256(password);
                    user.SecurityStamp = System.DateTime.Now.Ticks.ToString();
                    result             = userStore.UpdateAsync(user).Result;
                }
                if (result == "OK")
                {
                    BackendUserService bus         = new BackendUserService();
                    BackendUser        userBackend = new BackendUser();
                    userBackend.Cognome       = cognome.Trim().ToUpper();
                    userBackend.Nome          = nome.Trim().ToUpper();
                    userBackend.UserName      = userName.Trim().ToUpper();
                    userBackend.Domain        = domain;
                    userBackend.CodiceFiscale = codicefiscale.Trim().ToUpper();
                    userBackend.UserId        = long.Parse(user.Id);
                    bus.Update(userBackend);
                    model.success = "true";
                }
                else
                {
                    model.success = "false";
                    model.message = "Utente non aggiornato";
                    return(this.Request.CreateResponse <UsersMailModel>(HttpStatusCode.OK, model));
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException("Errore aggiornamento utente. Dettaglio: " + ex.Message +
                                                                "StackTrace: " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : " vuoto "),
                                                                "ERR322",
                                                                string.Empty,
                                                                string.Empty,
                                                                ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                    model.success = "false";
                    model.message = string.Format("Utente {0} non correttamente aggiornato", userName);
                    return(this.Request.CreateResponse <UsersMailModel>(HttpStatusCode.OK, model));
                }
                model.success = "false";
                model.message = ex.Message;
                return(this.Request.CreateResponse <UsersMailModel>(HttpStatusCode.OK, model));
            }
            return(this.Request.CreateResponse <UsersMailModel>(HttpStatusCode.OK, model));
        }
Ejemplo n.º 28
0
        public List <BackendUser> GetDipendentiDipartimentoAbilitati(Decimal idSender)
        {
            List <BackendUser> listaDipendenti = new List <BackendUser>();

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    using (var oCmd = dbcontext.Database.Connection.CreateCommand())
                    {
                        oCmd.CommandText = "SELECT MAIL_USERS_BACKEND.ID_USER, " +
                                           "MAIL_USERS_BACKEND.USER_NAME, " +
                                           "MAIL_USERS_BACKEND.COGNOME, " +
                                           "MAIL_USERS_BACKEND.NOME, " +
                                           "MAIL_USERS_BACKEND.DEPARTMENT, " +
                                           "MAIL_USERS_BACKEND.MUNICIPIO, " +
                                           "MAIL_USERS_BACKEND.DOMAIN, " +
                                           "MAIL_USERS_BACKEND.ROLE ROLE_USER, " +
                                           "MAIL_USERS_SENDER_BACKEND.REF_ID_SENDER ID_SENDER, " +
                                           "MAIL_USERS_SENDER_BACKEND.ROLE AS ROLE_MAIL " +
                                           "FROM  [FAXPEC].[FAXPEC].[MAIL_USERS_BACKEND],  [FAXPEC].[FAXPEC].[MAIL_USERS_SENDER_BACKEND] " +
                                           "WHERE MAIL_USERS_BACKEND.ID_USER = MAIL_USERS_SENDER_BACKEND.REF_ID_USER " +
                                           "AND MAIL_USERS_SENDER_BACKEND.REF_ID_SENDER = " + idSender +
                                           " ORDER BY MAIL_USERS_SENDER_BACKEND.DATA_INSERIMENTO DESC";
                        oCmd.Connection.Open();
                        using (var r = oCmd.ExecuteReader())
                        {
                            if (r.HasRows)
                            {
                                listaDipendenti = new List <BackendUser>();
                                while (r.Read())
                                {
                                    BackendUser bUser = AutoMapperConfiguration.MapToBackendUser(r);

                                    if (bUser != null && bUser.UserId >= 0)
                                    {
                                        BackEndUserMailUserMapping b = new BackEndUserMailUserMapping();
                                        b.MailSenderId    = (long)r.GetDecimal("ID_SENDER");
                                        b.MailAccessLevel = int.Parse(r.GetString("ROLE_MAIL"));
                                        List <BackEndUserMailUserMapping> bList = new List <BackEndUserMailUserMapping>();
                                        bList.Add(b);
                                        bUser.MappedMails = bList;
                                    }
                                    listaDipendenti.Add(bUser);
                                }
                            }
                        }
                        oCmd.Connection.Close();
                    }
                }
            }
            catch (Exception e)
            {
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione lista utenti abilitati per email: " + idSender.ToString() + " E072 Dettagli Errore: " + e.Message,
                                                                "ERR_072", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                }
                listaDipendenti = null;
            }

            return(listaDipendenti);
        }
Ejemplo n.º 29
0
        public List <BackendUser> GetDipendentiDipartimentoNONAbilitati(String dipartimento, Decimal idSender)
        {
            List <BackendUser> listaDipendenti = null;

            try
            {
                using (OracleCommand oCmd = base.CurrentConnection.CreateCommand())
                {
                    oCmd.CommandText = "SELECT DISTINCT MAIL_USERS_BACKEND.ID_USER, " +
                                       "MAIL_USERS_BACKEND.USER_NAME, " +
                                       "MAIL_USERS_BACKEND.COGNOME, " +
                                       "MAIL_USERS_BACKEND.NOME, " +
                                       "MAIL_USERS_BACKEND.DEPARTMENT, " +
                                       "MAIL_USERS_BACKEND.MUNICIPIO, " +
                                       "MAIL_USERS_BACKEND.DOMAIN, " +
                                       "0 as  ROLE_USER, " +
                                       "0 AS ROLE_MAIL" +
                                       " FROM MAIL_USERS_BACKEND " +
                                       " LEFT OUTER JOIN MAIL_USERS_SENDER_BACKEND ON ID_USER=REF_ID_USER " +
                                       " WHERE MAIL_USERS_BACKEND.ID_USER NOT IN " +
                                       " (SELECT MAIL_USERS_SENDER_BACKEND.REF_ID_USER FROM MAIL_USERS_SENDER_BACKEND " +
                                       "WHERE MAIL_USERS_SENDER_BACKEND.REF_ID_SENDER = :ID_SENDER) " +
                                       "AND MAIL_USERS_BACKEND.DEPARTMENT = :DEPARTMENT";

                    oCmd.Parameters.Add("ID_SENDER", idSender);
                    oCmd.Parameters.Add("DEPARTMENT", dipartimento);
                    using (OracleDataReader r = oCmd.ExecuteReader())
                    {
                        if (r.HasRows)
                        {
                            listaDipendenti = new List <BackendUser>();
                            while (r.Read())
                            {
                                BackendUser bUser = DaoOracleDbHelper.MapToBackendUser(r);
                                listaDipendenti.Add(bUser);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //TASK: Allineamento log - Ciro
                if (!e.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException("Errore nella creazione lista utenti non abilitati per email e dipartimento : " + idSender.ToString() + " " + dipartimento + " E074 Dettagli Errore: " + e.Message,
                                                                "ERR_074", string.Empty, string.Empty, e.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);

                    log.Error(err);
                }
                //Com.Delta.Logging.Errors.ErrorLogInfo error = new Com.Delta.Logging.Errors.ErrorLogInfo();
                //error.freeTextDetails = "Errore nella creazione lista utenti non abilitati per email e dipartimento : " + idSender.ToString() + " " + dipartimento + " E074 Dettagli Errore: " + e.Message;
                //error.logCode = "ERR_074";
                //error.passiveparentcodeobjectID = string.Empty;
                //error.passiveobjectGroupID = idSender.ToString();
                //error.passiveobjectID = string.Empty;
                //error.passiveapplicationID = string.Empty;
                //log.Error(error);
                listaDipendenti = null;
            }

            return(listaDipendenti);
        }
Ejemplo n.º 30
0
        public HttpResponseMessage GetOwnProfile()
        {
            BackendUserService buservice = new BackendUserService();
            UsersMailModel     model     = new UsersMailModel();
            string             UserName  = MySecurityProvider.CurrentPrincipal.MyIdentity.UserName;
            BackendUser        _bUser    = null;

            try
            {
                if (!(SessionManager <BackendUser> .exist(Com.Delta.Web.Session.SessionKeys.BACKEND_USER)))
                {
                    _bUser = (BackendUser)buservice.GetByUserName(MySecurityProvider.CurrentPrincipal.MyIdentity.UserName);
                    SessionManager <BackendUser> .set(Com.Delta.Web.Session.SessionKeys.BACKEND_USER, _bUser);
                }
                else
                {
                    _bUser = SessionManager <BackendUser> .get(Com.Delta.Web.Session.SessionKeys.BACKEND_USER);
                }
                if (_bUser != null)
                {
                    OwnProfile p = new OwnProfile();
                    p.Cognome       = _bUser.Cognome;
                    p.Department    = _bUser.Department;
                    p.Domain        = _bUser.Domain;
                    p.CodiceFiscale = _bUser.CodiceFiscale;
                    if (_bUser.MappedMails != null && _bUser.MappedMails.Count > 0)
                    {
                        p.MappedMails = new List <CasellaMail>();
                        List <CasellaMail> l = new List <CasellaMail>();
                        foreach (BackEndUserMailUserMapping b in _bUser.MappedMails)
                        {
                            CasellaMail m = new CasellaMail
                            {
                                idMail       = b.Id.ToString(),
                                emailAddress = b.Casella
                            };
                            l.Add(m);
                        }
                        p.MappedMails = l;
                    }
                    p.Nome               = _bUser.Nome;
                    p.RoleMail           = _bUser.RoleMail;
                    p.RoleMailDesription = (_bUser.RoleMail == 0) ? "Utente" : "Amministratore";
                    p.UserId             = (int)_bUser.UserId;
                    p.UserName           = _bUser.UserName;
                    p.UserRole           = _bUser.UserRole;
                    p.Password           = string.Empty;
                    var roleStore = new RoleStore();
                    var roles     = roleStore.GetRolesByUserId((int)_bUser.UserId).Result;
                    p.Roles           = roles;
                    model.OwnProfiles = new List <OwnProfile>();
                    model.OwnProfiles.Add(p);
                    model.success = "true";
                    model.Totale  = "1";
                }
                else
                {
                    model.success = "false";
                    model.message = "Utente non collegato a caselle di posta";
                }
            }
            catch (Exception ex)
            {
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ErrorLogInfo error = new ErrorLogInfo();
                    error.freeTextDetails = ex.Message;
                    error.logCode         = "ERR_U002";
                    error.loggingAppCode  = "PEC";
                    error.loggingTime     = System.DateTime.Now;
                    error.uniqueLogID     = System.DateTime.Now.Ticks.ToString();
                    log.Error(error);
                    model.message = ex.Message;
                    model.success = "false";
                }
                else
                {
                    model.message = ex.Message;
                    model.success = "false";
                }
            }
            return(this.Request.CreateResponse <UsersMailModel>(HttpStatusCode.OK, model));
        }