Example #1
0
        public async Task<IActionResult> PutConfigScreen([FromRoute] int id, [FromBody] ConfigScreen configScreen)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != configScreen.Id)
            {
                return BadRequest();
            }

            _context.Entry(configScreen).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConfigScreenExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Resources loading.
            TextureManager.Instance.Initialize(this);
            EffectManager.Instance.Initialize(this);
            FontManager.Instance.Initialize(this);

            // Components creation.
            this.CameraField          = new Camera(this);
            this.MapManagerField      = new MapManager(this);
            this.SpriteManagerField   = new SpriteManager(this);
            this.AreaManagerField     = new AreaManager(this.GraphicsDevice, this.Camera);
            this.ParticleManagerField = new ParticleManager(new Vector3(0, 0, -100), this.GraphicsDevice, this.Camera);
            this.DamageManagerField   = new DamageManager(this);

            // Debug
            this.ConsoleField    = new IRTaktiks.Components.Debug.Console(this);
            this.FPSField        = new FPS(this);
            this.TouchDebugField = new TouchDebug(this);

            AnimationManager.Instance.Initialize(this);

            // Screen construction.
            this.TitleScreenField   = new TitleScreen(this, 0);
            this.ConfigScreenField  = new ConfigScreen(this, 0);
            this.GameScreenField    = new GameScreen(this, 0);
            this.EndScreenField     = new EndScreen(this, 0);
            this.ScreenManagerField = new ScreenManager(this);

            // Map addicition.
            this.MapManager.Enabled = false;
            this.MapManager.Visible = false;
            this.Components.Add(this.MapManager);

            // Screen addiction.
            this.ScreenManager.Screens.Add(this.TitleScreen);
            this.ScreenManager.Screens.Add(this.ConfigScreen);
            this.ScreenManager.Screens.Add(this.GameScreen);
            this.ScreenManager.Screens.Add(this.EndScreen);

            // Components addiction.
            this.Components.Add(this.Camera);
            this.Components.Add(this.ScreenManager);

            // Debug
            this.Components.Add(this.Console);
            this.Components.Add(this.FPS);
            this.Components.Add(this.TouchDebug);

            // Change the game to its first status.
            this.ChangeScreen(GameScreens.TitleScreen);

            base.Initialize();
        }
Example #3
0
 public void UpdateAllBackgrounds()
 {
     MainScreen.UpdateBackground();
     ItemScreen.UpdateBackground();
     //MagicScreen.UpdateBackground();
     MateriaScreen.UpdateBackground();
     EquipScreen.UpdateBackground();
     StatusScreen.UpdateBackground();
     ConfigScreen.UpdateBackground();
     PhsScreen.UpdateBackground();
     SaveScreen.UpdateBackground();
 }
Example #4
0
        public async Task<IActionResult> PostConfigScreen([FromBody] ConfigScreen configScreen)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _context.ConfigScreens.Add(configScreen);
            await _context.SaveChangesAsync();

            return CreatedAtAction("GetConfigScreen", new { id = configScreen.Id }, configScreen);
        }
    public ScreensManager()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

        game       = new GameMain(1280, 720);
        welcomeScr = new WelcomeScreen(this);
        loadingScr = new LoadingScreen(this);
        creditsScr = new CreditsScreen(this);
        configScr  = new ConfigScreen(this);
        helpScr    = new HelpScreen(this);
        endScr     = new EndScreen(this);

        currentMode = MODE.LOADING;
    }
Example #6
0
    public static void Main(string[] args)
    {
        SdlHardware.Init(1280, 720, 24, false);

        LoadingScreen ls = new LoadingScreen();

        ls.Run();

        WelcomeScreen welcome = new WelcomeScreen();

        do
        {
            welcome.Run();
            if (welcome.GetChosenOption() == WelcomeScreen.OPTION_PLAY)
            {
                Game g = new Game();
                g.Run();
                EndScreen end = new EndScreen();
                end.Run();
            }
            else if (welcome.GetChosenOption() == WelcomeScreen.OPTION_HELP)
            {
                HelpScreen help = new HelpScreen();
                help.Run();
            }
            else if (welcome.GetChosenOption() == WelcomeScreen.OPTION_CREDITS)
            {
                CreditsScreen credits = new CreditsScreen();
                credits.Run();
            }
            else if (welcome.GetChosenOption() == WelcomeScreen.OPTION_CONFIG)
            {
                ConfigScreen config = new ConfigScreen();
                config.Run();
            }
        }while (welcome.GetChosenOption() != WelcomeScreen.OPTION_QUIT);
    }
Example #7
0
        public async Task <IActionResult> GetConfiguration([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            SecurityUser user = await _context.SecurityUsers.Where(x => x.Id == id).Include(x => x.Rol).ThenInclude(y => y.SecurityRoleActions).ThenInclude(y => y.SecurityAction).ThenInclude(y => y.SystemAction).Include(x => x.Rol).ThenInclude(z => z.SecurityRoleScreens).ThenInclude(z => z.ConfigScreen).ThenInclude(h => h.SystemScreen).Include(x => x.Rol).ThenInclude(z => z.SecurityRoleScreens).ThenInclude(z => z.ConfigScreen).ThenInclude(h => h.ConfigScreenFields).FirstOrDefaultAsync();

            if (user == null)
            {
                return(NotFound());
            }

            UserConfigurationViewModel viewModel = new UserConfigurationViewModel
            {
                Id             = user.Id,
                Nombre         = user.Nombre,
                SecurityRoleId = user.SecurityRoleId
            };

            //ROL

            SecurityRoleConfigurationViewModel rol = new SecurityRoleConfigurationViewModel
            {
                Id          = user.Rol.Id,
                Description = user.Rol.Description,
                Name        = user.Rol.Name,
                Screens     = new List <SecurityRoleScreenConfViewModel>()
            };

            //Screens
            if (user.Rol.SecurityRoleScreens != null)
            {
                foreach (var item in user.Rol.SecurityRoleScreens)
                {
                    ConfigScreen configScreen = item.ConfigScreen;
                    SecurityRoleScreenConfViewModel screen = new SecurityRoleScreenConfViewModel
                    {
                        Description    = configScreen.Description,
                        Enabled        = configScreen.Enabled,
                        Icon           = configScreen.Icon,
                        Id             = configScreen.Id,
                        Orden          = configScreen.Orden,
                        ParentId       = configScreen.SystemScreen.ParentId,
                        Path           = configScreen.SystemScreen.Path,
                        SystemScreenId = configScreen.SystemScreenId,
                        Actions        = new List <SecurityRoleActionConfViewModel>(),
                        Fields         = new List <ScreenFieldConfViewModel>()
                    };

                    foreach (var fields in configScreen.ConfigScreenFields)
                    {
                        ScreenFieldConfViewModel screenField = new ScreenFieldConfViewModel
                        {
                            DefaultValue = fields.DefaultValue,
                            Enabled      = fields.Enabled,
                            FieldName    = fields.FieldName,
                            Orden        = fields.Orden ?? 0,
                            Id           = fields.Id,
                            Name         = fields.Name,
                            Required     = fields.Required,
                            Visible      = fields.Visible
                        };
                        screen.Fields.Add(screenField);
                    }

                    foreach (var action in user.Rol.SecurityRoleActions)
                    {
                        if (action.SecurityAction.ConfigScreenId == screen.Id)
                        {
                            if (action.SecurityAction.Enabled)
                            {
                                SecurityRoleActionConfViewModel actionVm = new SecurityRoleActionConfViewModel
                                {
                                    Id          = action.SecurityActionId,
                                    Code        = action.SecurityAction.SystemAction.Code,
                                    Description = action.SecurityAction.Description
                                };
                                screen.Actions.Add(actionVm);
                            }
                        }
                    }
                    rol.Screens.Add(screen);
                }
            }

            viewModel.Role = rol;


            return(Ok(viewModel));
        }
Example #8
0
 public void Show(ConfigScreen configScreen)
 {
     language.SetTextData(configScreen.language);
     volume.SetTextData(configScreen.volume);
 }
Example #9
0
        public async Task <IActionResult> Update([FromBody] UpdateCompanyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                string strRuta = _config["AvatarFiles"];

                Company company = await _context.Companies.Include(x => x.CompanySectors).Include(x => x.SecurityRoles).ThenInclude(x => x.SecurityRoleScreens).Include(x => x.SecurityRoles).ThenInclude(x => x.SecurityRoleActions).Include(x => x.ConfigScreen).ThenInclude(x => x.SecurityActions).Include(x => x.ConfigScreen).ThenInclude(x => x.ConfigScreenFields).Where(x => x.Id == model.Id).FirstOrDefaultAsync();

                var listRoles = company.SecurityRoles;
                if (company == null)
                {
                    return(BadRequest("Compania inexistente"));
                }

                //Actualizo la compania
                company.Name            = model.Name;
                company.ContactName     = model.ContactName;
                company.ContactLastName = model.ContactLastName;
                company.InitialDate     = model.InitialDate;
                company.Email           = model.Email;
                company.Phone           = model.Phone;
                company.Website         = model.Website;
                company.Address         = model.Address;
                company.Postal          = model.Postal;
                company.City            = model.City;
                company.State           = model.State;
                company.Country         = model.Country;
                company.Schedule        = model.Schedule;
                company.Comment         = model.Comment;

                ////Guardo el avatar
                if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo)))
                {
                    strRuta = strRuta + "//" + company.Id.ToString() + "//" + model.LogoName;
                    System.IO.FileInfo file = new System.IO.FileInfo(strRuta);
                    file.Directory.Create();
                    System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1)));
                    company.Logo = strRuta;
                }


                //Sectores
                var sectorToBeAdded = model.CompanySectors.Where(a => company.CompanySectors.All(
                                                                     b => b.SectorId != a.SectorId));

                var sectorToBeDeleted = company.CompanySectors.Where(a => model.CompanySectors.All(
                                                                         b => b.SectorId != a.SectorId));

                foreach (var sector in sectorToBeDeleted)
                {
                    company.CompanySectors.Remove(sector);
                }

                foreach (var sector in sectorToBeAdded)
                {
                    company.CompanySectors.Add(sector);
                }

                //Screens
                //Solo vienen las activas
                var screenToBeAdded = model.ConfigScreens.Where(a => company.ConfigScreen.All(
                                                                    b => b.SystemScreenId != a.SystemScreenId));

                var screenToBeDeleted = company.ConfigScreen.Where(a => model.ConfigScreens.All(
                                                                       b => b.SystemScreenId != a.SystemScreenId));


                //Si no se dan de alta o se eliminan, los actualizo
                //son todos los que no se graban + los que no se eliminan
                List <ConfigScreen> screenNotbeUpdated = new List <ConfigScreen>();
                List <ConfigScreen> screenEnabled      = new List <ConfigScreen>();
                screenNotbeUpdated.AddRange(screenToBeAdded);
                screenNotbeUpdated.AddRange(screenToBeDeleted);
                var screenToBeUpdated = model.ConfigScreens.Where(a => screenNotbeUpdated.All(
                                                                      b => b.SystemScreenId != a.SystemScreenId));

                screenEnabled.AddRange(screenToBeAdded);
                screenEnabled.AddRange(screenToBeUpdated);

                //Elimino las pantallas del paso 2
                foreach (var screenDtl in screenToBeDeleted.ToList())
                {
                    //Borro los childs
                    ConfigScreen configScreen = company.ConfigScreen.Where(x => x.SystemScreenId == screenDtl.SystemScreenId).FirstOrDefault();
                    //Seteo las dependencias
                    var securityactionsToDelete   = configScreen.SecurityActions;
                    var configScreenFieldToDelete = configScreen.ConfigScreenFields;


                    //Borro las acciones
                    foreach (var action in securityactionsToDelete.ToList())
                    {
                        configScreen.SecurityActions.Remove(action);
                    }

                    //Borro los atributos
                    foreach (var attr in configScreenFieldToDelete.ToList())
                    {
                        configScreen.ConfigScreenFields.Remove(attr);
                    }

                    var listRolesToDelete = listRoles;

                    //Borro las pantallas de los roles
                    foreach (var item in listRolesToDelete.ToList())
                    {
                        var listRolesActionToDelete = item.SecurityRoleActions.Where(x => x.SecurityAction.ConfigScreen.SystemScreenId == screenDtl.SystemScreenId).ToList();
                        foreach (var action in listRolesActionToDelete)
                        {
                            item.SecurityRoleActions.Remove(action);
                        }

                        var listRolesScreenToDelete = item.SecurityRoleScreens.Where(x => x.ConfigScreen.SystemScreenId == screenDtl.SystemScreenId).ToList();
                        foreach (var screen in listRolesScreenToDelete)
                        {
                            item.SecurityRoleScreens.Remove(screen);
                        }
                    }

                    company.ConfigScreen.Remove(configScreen);
                }

                //Modifico
                foreach (var screen in company.ConfigScreen)
                {
                    ConfigScreen configScreen = screenToBeUpdated.Where(x => x.SystemScreenId == screen.SystemScreenId).FirstOrDefault();
                    if (configScreen != null)
                    {
                        screen.Description = configScreen.Description;
                        screen.Enabled     = configScreen.Enabled;
                        screen.Icon        = configScreen.Icon;
                        screen.Orden       = configScreen.Orden;
                    }

                    //Actualizo los fields
                    if (configScreen.ConfigScreenFields != null)
                    {
                        foreach (var item2 in configScreen.ConfigScreenFields)
                        {
                            bool existField = false;
                            foreach (var item1 in screen.ConfigScreenFields)
                            {
                                //Me fijo si esta creado, si esta lo actualizo
                                if (item1.SystemScreenFieldId == item2.SystemScreenFieldId)
                                {
                                    item1.Enabled      = item2.Enabled;
                                    item1.DefaultValue = item2.DefaultValue;
                                    item1.Orden        = item2.Orden;
                                    item1.FieldName    = item2.FieldName;
                                    item1.Name         = item2.Name;
                                    item1.Required     = item2.Required;
                                    item1.Visible      = item2.Visible;
                                    existField         = true;
                                    break;
                                }
                            }

                            //Sino existe lo creo
                            if (!existField)
                            {
                                ConfigScreenField configScreenField = new ConfigScreenField
                                {
                                    Enabled             = item2.Enabled,
                                    DefaultValue        = item2.DefaultValue,
                                    Orden               = item2.Orden,
                                    FieldName           = item2.FieldName,
                                    Name                = item2.Name,
                                    Required            = item2.Required,
                                    Visible             = item2.Visible,
                                    ConfigScreenId      = item2.ConfigScreenId,
                                    SystemScreenFieldId = item2.SystemScreenFieldId
                                };
                                screen.ConfigScreenFields.Add(configScreenField);
                            }
                        }
                    }

                    //Actualizo las acciones
                    if (configScreen.SecurityActions != null)
                    {
                        foreach (var item2 in configScreen.SecurityActions)
                        {
                            bool existAction = false;
                            foreach (var item1 in screen.SecurityActions)
                            {
                                if (item1.SystemActionId == item2.SystemActionId)
                                {
                                    item1.Enabled     = item2.Enabled;
                                    item1.Description = item2.Description;
                                    existAction       = true;
                                    break;
                                }
                            }

                            //Sino existe lo creo
                            if (!existAction)
                            {
                                SecurityAction securityAction = new SecurityAction
                                {
                                    Enabled        = item2.Enabled,
                                    Description    = item2.Description,
                                    ConfigScreenId = item2.ConfigScreenId,
                                    SystemActionId = item2.SystemActionId
                                };
                                screen.SecurityActions.Add(securityAction);
                            }
                        }
                    }
                }


                //Agrego
                foreach (var screenAdd in screenToBeAdded.ToList())
                {
                    ConfigScreen configScreenAdd = new ConfigScreen
                    {
                        CompanyId      = model.Id,
                        Description    = screenAdd.Description,
                        Enabled        = screenAdd.Enabled,
                        Orden          = screenAdd.Orden,
                        Icon           = screenAdd.Icon,
                        SystemScreenId = screenAdd.SystemScreenId
                    };

                    //tambien agrego los atributos

                    //Dentro de las pantallas agrego los Atributos
                    if (screenAdd.ConfigScreenFields != null)
                    {
                        configScreenAdd.ConfigScreenFields = new List <ConfigScreenField>();

                        foreach (var field in screenAdd.ConfigScreenFields)
                        {
                            ConfigScreenField configScreenField = new ConfigScreenField
                            {
                                ConfigScreenId      = screenAdd.Id,
                                Name                = field.Name,
                                Required            = field.Required,
                                Visible             = field.Visible,
                                DefaultValue        = field.DefaultValue,
                                Orden               = field.Orden,
                                Enabled             = field.Enabled,
                                FieldName           = field.FieldName,
                                SystemScreenFieldId = field.SystemScreenFieldId,
                            };
                            configScreenAdd.ConfigScreenFields.Add(configScreenField);
                        }
                    }

                    //Dentro de las pantallas agrego las Acciones
                    if (screenAdd.SecurityActions != null)
                    {
                        configScreenAdd.SecurityActions = new List <SecurityAction>();
                        foreach (var action in screenAdd.SecurityActions)
                        {
                            SecurityAction securityAction = new SecurityAction
                            {
                                ConfigScreenId = screenAdd.Id,
                                Description    = action.Description,
                                Enabled        = action.Enabled,
                                SystemActionId = action.SystemActionId,
                            };
                            configScreenAdd.SecurityActions.Add(securityAction);
                        }
                    }



                    company.ConfigScreen.Add(configScreenAdd);
                }


                _context.Entry(company).State = EntityState.Modified;
                await _context.SaveChangesAsync();


                //SecurityRoles
                //Vienen todos los roles
                foreach (var modelRol in model.SecurityRoles.ToList())
                {
                    //Paso 5
                    SecurityRole securityRole = company.SecurityRoles.Where(x => x.SystemRoleId == modelRol.SystemRoleId).FirstOrDefault();

                    if (securityRole != null)
                    {
                        securityRole.Description = modelRol.Description;
                        securityRole.Name        = modelRol.Name;
                        securityRole.Enabled     = modelRol.Enabled;

                        var screenRolToBeAdded = modelRol.SecurityRoleScreens.Where(a => securityRole.SecurityRoleScreens.All(
                                                                                        b => b.ConfigScreen.SystemScreenId != a.SystemScreenId));

                        var screenRolToBeDeleted = securityRole.SecurityRoleScreens.Where(a => modelRol.SecurityRoleScreens.All(
                                                                                              b => b.SystemScreenId != a.ConfigScreen.SystemScreenId));

                        var actionRolToBeAdded = modelRol.SecurityRoleActions.Where(a => securityRole.SecurityRoleActions.All(
                                                                                        b => b.SecurityAction.SystemActionId != a.SystemActionId));

                        var actionRolToBeDeleted = securityRole.SecurityRoleActions.Where(a => modelRol.SecurityRoleActions.All(
                                                                                              b => b.SystemActionId != a.SecurityAction.SystemActionId));

                        //SCREENS
                        foreach (var item in screenRolToBeDeleted.ToList())
                        {
                            securityRole.SecurityRoleScreens.Remove(item);
                        }

                        foreach (var item2 in screenRolToBeAdded.ToList())
                        {
                            SecurityRoleScreen securityRoleScreen = new SecurityRoleScreen
                            {
                                SecurityRoleId = item2.SystemRoleId,
                                ConfigScreenId = company.ConfigScreen.Where(x => x.SystemScreenId == item2.SystemScreenId).Select(x => x.Id).FirstOrDefault()
                            };

                            securityRole.SecurityRoleScreens.Add(securityRoleScreen);
                        }

                        //ACCIONES
                        foreach (var item in actionRolToBeDeleted.ToList())
                        {
                            securityRole.SecurityRoleActions.Remove(item);
                        }

                        foreach (var item2 in actionRolToBeAdded.ToList())
                        {
                            var configScreen = company.ConfigScreen.Where(x => x.SystemScreenId == item2.SystemScreenId).FirstOrDefault();
                            if (configScreen != null)
                            {
                                foreach (var action in configScreen.SecurityActions)
                                {
                                    if (item2.SystemActionId == action.SystemActionId)
                                    {
                                        SecurityRoleAction securityRoleAction = new SecurityRoleAction
                                        {
                                            SecurityRoleId = item2.SystemRoleId
                                        };
                                        securityRoleAction.SecurityActionId = action.Id;
                                        securityRole.SecurityRoleActions.Add(securityRoleAction);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                _context.Entry(company).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Example #10
0
        public async Task <IActionResult> Create([FromBody] CreateCompanyViewModel model)
        {
            string userPassword = CreatePassword(6);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                string  strRuta = _config["AvatarFiles"];
                Company company = new Company
                {
                    Name            = model.Name,
                    ContactName     = model.ContactName,
                    ContactLastName = model.ContactLastName,
                    InitialDate     = model.InitialDate,
                    Email           = model.Email,
                    Phone           = model.Phone,
                    Website         = model.Website,
                    Address         = model.Address,
                    Postal          = model.Postal,
                    City            = model.City,
                    State           = model.State,
                    Country         = model.Country,
                    Schedule        = model.Schedule,
                    Comment         = model.Comment,
                    CreationDate    = DateTime.Now,
                    Enabled         = true
                };


                //Agrego los sectores
                if (model.CompanySectors != null)
                {
                    company.CompanySectors = new List <CompanySector>();
                    foreach (var sector in model.CompanySectors)
                    {
                        CompanySector companySector = new CompanySector
                        {
                            CompanyId = company.Id,
                            SectorId  = sector.SectorId
                        };
                        company.CompanySectors.Add(companySector);
                    }
                }


                //Agrego las pantallas
                if (model.ConfigScreens != null)
                {
                    company.ConfigScreen = new List <ConfigScreen>();
                    foreach (var item in model.ConfigScreens)
                    {
                        ConfigScreen configScreen = new ConfigScreen
                        {
                            CompanyId      = company.Id,
                            Description    = item.Description,
                            Enabled        = item.Enabled,
                            Orden          = item.Orden,
                            Icon           = item.Icon,
                            SystemScreenId = item.SystemScreenId
                        };

                        //Dentro de las pantallas agrego los Atributos
                        if (item.ConfigScreenFields != null)
                        {
                            configScreen.ConfigScreenFields = new List <ConfigScreenField>();
                            foreach (var field in item.ConfigScreenFields)
                            {
                                ConfigScreenField configScreenField = new ConfigScreenField
                                {
                                    ConfigScreenId      = item.Id,
                                    Name                = field.Name,
                                    Required            = field.Required,
                                    Visible             = field.Visible,
                                    DefaultValue        = field.DefaultValue,
                                    Orden               = field.Orden,
                                    Enabled             = field.Enabled,
                                    FieldName           = field.FieldName,
                                    SystemScreenFieldId = field.SystemScreenFieldId,
                                };
                                configScreen.ConfigScreenFields.Add(configScreenField);
                            }
                        }

                        //Dentro de las pantallas agrego las Acciones
                        if (item.SecurityActions != null)
                        {
                            configScreen.SecurityActions = new List <SecurityAction>();
                            foreach (var action in item.SecurityActions)
                            {
                                SecurityAction securityAction = new SecurityAction
                                {
                                    ConfigScreenId = item.Id,
                                    Description    = action.Description,
                                    Enabled        = action.Enabled,
                                    SystemActionId = action.SystemActionId,
                                };
                                configScreen.SecurityActions.Add(securityAction);
                            }
                        }

                        company.ConfigScreen.Add(configScreen);
                    }
                }



                _context.Companies.Add(company);
                await _context.SaveChangesAsync();



                //Agrego los roles
                ////Agrego las pantallas que aplican para ese rol
                company.SecurityRoles = new List <SecurityRole>();

                foreach (var rol in model.SecurityRoles)
                {
                    int          i            = 0;
                    SecurityRole securityRole = new SecurityRole
                    {
                        Name         = rol.Name,
                        CompanyId    = company.Id,
                        Description  = rol.Description,
                        Enabled      = true,
                        SystemRoleId = rol.SystemRoleId
                    };


                    if (i == 0)
                    {
                        //Genero el usuario
                        securityRole.Usuarios = new List <SecurityUser>();


                        CrearPasswordHash(userPassword, out byte[] passwordHash, out byte[] passwordSalt);

                        SecurityUser user = new SecurityUser
                        {
                            CompanyId      = company.Id,
                            Condicion      = true,
                            Direccion      = company.Address,
                            Email          = company.Email,
                            Nombre         = company.Name,
                            SecurityRoleId = securityRole.Id,
                            Password_hash  = passwordHash,
                            Password_salt  = passwordSalt
                        };

                        securityRole.Usuarios.Add(user);
                    }
                    i++;


                    securityRole.SecurityRoleScreens = new List <SecurityRoleScreen>();
                    securityRole.SecurityRoleActions = new List <SecurityRoleAction>();
                    foreach (var screen in company.ConfigScreen)
                    {
                        //Si la pantalla esta en el rol, la agrego
                        if (rol.SecurityRoleScreens.Where(x => x.SystemScreenId == screen.SystemScreenId).Any())
                        {
                            SecurityRoleScreen securityRoleScreen = new SecurityRoleScreen
                            {
                                ConfigScreenId = screen.Id,
                                SecurityRoleId = securityRole.Id
                            };
                            securityRole.SecurityRoleScreens.Add(securityRoleScreen);


                            foreach (var action in screen.SecurityActions)
                            {
                                if (rol.SecurityRoleActions.Where(x => x.SystemActionId == action.SystemActionId).Any())
                                {
                                    SecurityRoleAction securityRoleAction = new SecurityRoleAction
                                    {
                                        SecurityActionId = action.Id,
                                        SecurityRoleId   = securityRole.Id
                                    };
                                    securityRole.SecurityRoleActions.Add(securityRoleAction);
                                }
                            }
                        }
                    }


                    company.SecurityRoles.Add(securityRole);
                }

                //Guardo el avatar
                if (company.Id > 0)
                {
                    if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo)))
                    {
                        strRuta = strRuta + "//" + company.Id.ToString() + "//" + model.LogoName;
                        System.IO.FileInfo file = new System.IO.FileInfo(strRuta);
                        file.Directory.Create();
                        System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1)));
                        company.Logo = strRuta;
                    }
                }

                _context.Entry(company).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }

            return(Ok(userPassword));
        }