Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] CreateCustomerViewModel model)
        {
            string strRuta = _config["CustomerAvatar"];

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Customer modelo = new Customer
            {
                CompanyId      = model.CompanyId,
                Enabled        = true,
                Address        = model.Address,
                CountryId      = model.CountryId,
                StateId        = model.StateId,
                CityId         = model.CityId,
                Names          = model.Names,
                Phone          = model.Phone,
                DateInitial    = DateTime.Now,
                Documento      = model.Documento,
                DocumentTypeId = model.DocumentTypeId,
                Email          = model.Email,
                Favorite       = model.Favorite,
                Observation    = model.Observation,
                PriceListId    = model.PriceListId
            };


            _context.Customers.Add(modelo);
            try
            {
                await _context.SaveChangesAsync();


                //Guardo el avatar
                if (modelo.Id > 0)
                {
                    if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo)))
                    {
                        strRuta = strRuta + "//" + modelo.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)));
                        modelo.Logo = strRuta;
                    }
                }

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

            return(Ok());
        }
Beispiel #2
0
        public IActionResult OnPost(int idUsuario, string claveServ, string dato)
        {
            ServicioDeMensajeria servicio = new ServicioDeMensajeria();

            servicio.Dato      = dato;
            servicio.IdUsuario = idUsuario;
            switch (claveServ)
            {
            case "cel":     //Numero de celular
                servicio.Servicio = 1;
                break;

            case "wh":     //WhatsApp
                servicio.Servicio = 2;
                break;

            case "teleg":     //Telegram
                servicio.Servicio = 3;
                break;

            case "fbm":     //Facebook Messenger
                servicio.Servicio = 4;
                break;
            }
            contexto.ServiciosDeMensajeria.Add(servicio);
            contexto.SaveChanges();
            contexto.Entry(servicio).GetDatabaseValues();
            IdServicio = servicio.Id;
            return(Page());
        }
Beispiel #3
0
        public async Task <IActionResult> PutSecurityRoleAction([FromRoute] int id, [FromBody] SecurityRoleAction securityRoleAction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Beispiel #4
0
        public async Task<IActionResult> PutTrackerLog([FromRoute] Int64 id, [FromBody] TrackerLog trackerLog)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return NoContent();
        }
Beispiel #5
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();
        }
Beispiel #6
0
        public IActionResult OnPost(string id, string pass, string Nombre, string Categoria, string precio, string Descripcion = "")
        {
            var ProductoNuevo = new Producto();

            ProductoNuevo.Nombre      = Nombre;
            ProductoNuevo.Descripcion = Descripcion;
            ProductoNuevo.Categoria   = Categoria;
            ProductoNuevo.Precio      = float.Parse(precio);
            ProductoNuevo.IdUsuario   = int.Parse(id);
            ProductoNuevo.Publico     = true;

            if (contexto.Usuarios.Find(int.Parse(id)).Password.Equals(pass))
            {
                contexto.Productos.Add(ProductoNuevo);
                contexto.SaveChanges();
                contexto.Entry(ProductoNuevo).GetDatabaseValues();
                Id           = ProductoNuevo.Id;
                ExistioError = false;
            }
            else
            {
                ExistioError = true;
            }

            return(Page());
        }
Beispiel #7
0
 public void Edit(SeverityModel model)
 {
     using (DbContextApp db = new DbContextApp())
     {
         var modelToUpdate = db.Severities.Single(m => m.ID == model.ID);
         db.Entry(modelToUpdate).CurrentValues.SetValues(model);
         db.SaveChanges();
     }
 }
Beispiel #8
0
        public async Task <IActionResult> Update([FromBody] UpdateExchangeCurrencyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model.Id <= 0)
            {
                return(BadRequest());
            }

            var modelo = await _context.ExchangeCurrencies.FirstOrDefaultAsync(x => x.Id == model.Id);

            modelo.Description = model.Description;
            modelo.DateEnd     = model.DateEnd;
            modelo.Quote       = model.Quote;



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

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //Guardar Exception
                return(BadRequest());
            }

            return(Ok());
        }
Beispiel #9
0
        public async Task <IActionResult> Create([FromBody] CreateProductViewModel model)
        {
            string strRuta = _config["ProductAvatar"];


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!string.IsNullOrEmpty(model.Codigo))
            {
                //Verifico si el codigo existe
                if (_context.Products.Where(x => x.Codigo == model.Codigo.ToUpper().Trim()).Any())
                {
                    return(BadRequest(new { Message = "Código repetido" }));
                }
            }



            Product modelo = new Product
            {
                Awaiting           = model.Awaiting ?? false,
                BrandId            = model.BrandId,
                CategoryId         = model.CategoryId,
                Codigo             = model.Codigo?.ToUpper().Trim(),
                CompanyId          = model.CompanyId,
                Cost               = model.Cost,
                DateInitial        = DateTime.Now,
                Description        = model.Description,
                Discount           = model.Discount ?? 0,
                Enabled            = true,
                ExchangeCurrencyId = model.ExchangeCurrencyId,
                Gain               = model.Gain,
                InStock            = model.InStock ?? false,
                LocationId         = model.LocationId,
                Name               = model.Name?.Trim(),
                NameShort          = model.NameShort?.Trim(),
                OutOfStock         = model.OutOfStock ?? false,
                Price              = model.Price ?? 0,
                Stock              = model.Stock,
                StockMin           = model.StockMin,
                SubCategoryId      = model.SubCategoryId,
                CheckStock         = model.CheckStock ?? false,
                ProductProviders   = new List <ProductProviders>(),
                ProductPriceLists  = new List <ProductPriceLists>()
            };

            foreach (var prov in model.Providers)
            {
                ProductProviders productProviders = new ProductProviders
                {
                    ProviderId = prov,
                    ProductId  = modelo.Id
                };

                modelo.ProductProviders.Add(productProviders);
            }

            foreach (var price in model.ProductPriceLists)
            {
                ProductPriceLists productPriceLists = new ProductPriceLists
                {
                    PriceListId = price.PriceList,
                    ProductId   = modelo.Id,
                    Price       = price.Price
                };
                modelo.ProductPriceLists.Add(productPriceLists);
            }

            _context.Products.Add(modelo);
            try
            {
                await _context.SaveChangesAsync();



                if (modelo.Id > 0)
                {
                    //Codigo
                    if (string.IsNullOrEmpty(modelo.Codigo))
                    {
                        modelo.Codigo = modelo.Id.ToString();
                    }

                    //Guardo el avatar
                    if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo)))
                    {
                        strRuta = strRuta + "//" + modelo.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)));
                        modelo.Logo = strRuta;
                    }
                }

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

            return(Ok());
        }
Beispiel #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));
        }