public IHttpActionResult Get()
 {
     try
     {
         using (BD_DWHEntities db = new BD_DWHEntities())
         {
             var lsContract = db.Contract
                              .Select(
                 ctr => new ContractViewModel {
                 id          = ctr.contract_id,
                 description = ctr.contract_description,
                 client      = new ClientViewModel {
                     document = ctr.cli_document, name = ctr.Client.cli_name
                 },
                 actCode        = ctr.contract_actCode,
                 startDate      = ctr.contract_startDate,
                 endingDate     = ctr.contract_endingDate,
                 renovationDate = ctr.contract_renovationDate,
                 signatureDate  = ctr.contract_signatureDate,
                 state          = ctr.contract_state
             }
                 )
                              .ToList();
             return(Ok(lsContract));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public IHttpActionResult Get()
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsClient = db.Client.Where(cl => cl.cli_state == true)
                                   .Select(cl => new ClientViewModel
                    {
                        document         = cl.cli_document,
                        name             = cl.cli_name,
                        lastName         = cl.cli_lastName,
                        economicActivity = new EconomicActivityViewModel {
                            id          = cl.EconomicActivity.ea_id,
                            description = cl.EconomicActivity.ea_description,
                            code        = cl.EconomicActivity.ea_code
                        },
                        city = new CityViewModel {
                            id       = cl.Cities.cty_id,
                            name     = cl.Cities.cty_name,
                            DANECode = cl.Cities.cty_dane_code
                        }
                    })
                                   .DefaultIfEmpty()
                                   .ToList();

                    return(Ok(lsClient));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #3
0
        public IHttpActionResult GetPermissionByRole(int role_id)
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsPermissionByRole = db.permissionByRole.Where(pm => pm.rol_id == role_id)
                                             .Select(pm => new PermissionByModuleViewModel
                    {
                        id     = pm.permByRol_id,
                        module = new ModuleViewModel {
                            id          = pm.permissionByModule.modules.mdl_id,
                            name        = pm.permissionByModule.modules.mdl_name,
                            description = pm.permissionByModule.modules.mdl_description
                        },
                        //permission = new PermissionViewModel {
                        //													id = pm.permissionByModule.permission.perm_id,
                        //													name = pm.permissionByModule.permission.perm_name }
                    }).ToList();


                    return(Ok(lsPermissionByRole));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult SavePermissionByRol(PermissionByRoleViewModel permByRol)
        {
            try
            {
                var message = "Hola";
                //TODO: Delete current permission by rol
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    //Primero debemos eliminar los permisos actuales y luego si agregar los nuevos permisos
                    var lsActualPermission = db.permissionByRole.Where(p => p.rol_id == permByRol.rol.id).ToList();

                    foreach (var permToDelete in lsActualPermission)
                    {
                        db.permissionByRole.Remove(permToDelete);
                        db.SaveChanges();
                    }

                    foreach (var perByMod in permByRol.permissionByModule)
                    {
                        var pbr = new permissionByRole();
                        pbr.rol_id = (int)permByRol.rol.id;

                        foreach (var permission in perByMod.lsPermission)
                        {
                            var permByMdl = db.permissionByModule.Where(pbm => pbm.mdl_id == perByMod.module.id && pbm.perm_id == permission.id)
                                            .FirstOrDefault();

                            pbr.permByMdl_id = permByMdl.permByMdl_id;
                            db.permissionByRole.Add(pbr);
                            db.SaveChanges();
                        }
                    }
                    ResponseViewModel rta = new ResponseViewModel();
                    rta.response = true;
                    rta.message  = "Se actualizan los permisos del rol: " + permByRol.rol.name;
                    return(Ok(rta));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult GetContactsByClient(string pClient_id)
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsContacts = new List <ContactViewModel>();
                    var branch     = db.branch.Where(b => b.cli_document == pClient_id).Select(b => new BranchViewModel {
                        id = b.bra_id, name = b.bra_name
                    }).FirstOrDefault();
                    var lsTmp = db.Contact.Where(ct => ct.bra_id == branch.id).Count();

                    if (lsTmp > 0)
                    {
                        lsContacts = db.Contact.Where(ct => ct.bra_id == branch.id)
                                     .Select(ct =>
                                             new ContactViewModel
                        {
                            id        = ct.cnt_id,
                            name      = ct.cnt_name,
                            lastName  = ct.cnt_lastName,
                            phone     = ct.cnt_phone,
                            cellPhone = ct.cnt_cellPhone,
                            email     = ct.cnt_email,
                            jobTitle  = new JobTitleViewModel {
                                id = ct.JobTitlesClient.jtcl_id, description = ct.JobTitlesClient.jtcl_description
                            },
                            adress = ct.cnt_adress,
                            branch = new BranchViewModel {
                                id = ct.branch.bra_id, name = ct.branch.bra_name
                            }
                        }
                                             ).ToList();
                    }

                    return(Ok(lsContacts));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
 public IHttpActionResult Get()
 {
     try
     {
         using (BD_DWHEntities db = new BD_DWHEntities()) {
             var lsVehicle = db.vehicle
                             .Select(vh =>
                                     new VehicleViewModel
             {
                 licensePlate       = vh.veh_licensePlate,
                 brand              = vh.veh_brand,
                 model              = vh.veh_model,
                 year               = vh.veh_year,
                 chasisCode         = vh.veh_chassisCode,
                 engineCode         = vh.veh_engineCode,
                 loadingCapacity    = vh.veh_loadingCapacity,
                 cylinder           = vh.veh_cylinder,
                 clasification      = vh.veh_clasification,
                 color              = vh.veh_color,
                 passangerCapacity  = vh.veh_passangerCapacity,
                 serviceType        = vh.veh_serviceType,
                 mileage            = vh.veh_mileage,
                 status             = vh.veh_status,
                 purchaseDate       = vh.veh_purchaseDate,
                 accesoriesPrice    = vh.veh_accesoriesPrice,
                 deliveredDate      = vh.veh_deliveredDate,
                 lastInspectionDate = vh.veh_lastInspectionDate,
                 provider           = new AllyViewModel {
                     document = vh.ally_id
                 },
                 contract         = vh.contract_id,
                 contratedMileage = vh.veh_contratedMileage
             }
                                     ).ToList();
             return(Ok(lsVehicle));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #7
0
        public IHttpActionResult Get()
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsRoles = db.roles
                                  .Select(rl => new RolViewModel {
                        id = rl.rol_id, name = rl.rol_name, description = rl.rol_description
                    })
                                  .ToList();

                    return(Ok(lsRoles));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult GetPermissionByModule()
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsModules = db.modules.Select(mdl => new ModuleViewModel {
                        id = mdl.mdl_id, name = mdl.mdl_name
                    })
                                    .ToList();

                    var lsPermissionByModule = new List <PermissionByModuleViewModel>();

                    foreach (ModuleViewModel module in lsModules)
                    {
                        PermissionByModuleViewModel permByMod = new PermissionByModuleViewModel();

                        var lsPermission = new List <PermissionViewModel>();
                        lsPermission = db.permissionByModule.Where(perm => perm.mdl_id == module.id)
                                       .Select(perm => new PermissionViewModel
                        {
                            id          = perm.perm_id,
                            name        = perm.permission.perm_name,
                            description = perm.permission.perm_description
                        }).ToList();


                        permByMod.module       = module;
                        permByMod.lsPermission = lsPermission;

                        lsPermissionByModule.Add(permByMod);
                    }

                    return(Ok(lsPermissionByModule));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult Get()
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities()) {
                    var lsUsers = db.users.Where(usu => usu.usu_state == true)
                                  .Select(usu => new UserViewModel {
                        document       = usu.usu_document,
                        kindOfDocument = new KindOfDocumentViewModel {
                            id = usu.kod_id, description = usu.kindOfDocument.kod_description
                        },
                        name      = usu.usu_name,
                        lastName  = usu.usu_lastName,
                        email     = usu.usu_email,
                        cellPhone = usu.usu_cellphone,
                        adress    = usu.usu_adress,
                        city      = new CityViewModel {
                            id = usu.cty_id, name = usu.Cities.cty_name
                        },
                        jobTitle = new JobTitleViewModel {
                            id = usu.jt_id, description = usu.jobTitle.jt_description
                        },
                        rol = new RolViewModel {
                            id = usu.rol_id, name = usu.roles.rol_name, description = usu.roles.rol_description
                        }
                    })
                                  .ToList();

                    return(Ok(lsUsers));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult authUser(LoginViewModel loginUserRA)
        {
            try
            {
                ResponseViewModel resp = new ResponseViewModel();

                using (BD_DWHEntities db = new BD_DWHEntities()) {
                    var userAuth = db.logins.Where(lg => lg.log_userName == loginUserRA.userName && lg.log_password == loginUserRA.password)
                                   .FirstOrDefault();

                    if (userAuth != null)
                    {
                        var user = db.users.Where(u => u.usu_document == userAuth.usu_document)
                                   .Select(u => new UserViewModel
                        {
                            document       = u.usu_document,
                            kindOfDocument = new KindOfDocumentViewModel {
                                id = u.kod_id, description = u.kindOfDocument.kod_description
                            },
                            name      = u.usu_name,
                            lastName  = u.usu_lastName,
                            cellPhone = u.usu_cellphone,
                            email     = u.usu_email
                        })
                                   .FirstOrDefault();

                        var rolByUser = db.userByRol.Where(rl => rl.usu_document == user.document)
                                        .Select(rl => new RolViewModel {
                            id = rl.roles.rol_id, name = rl.roles.rol_name, description = rl.roles.rol_description
                        })
                                        .FirstOrDefault();

                        user.rol = rolByUser;

                        var permissionByRol = db.permissionByRole.Where(perm => perm.rol_id == rolByUser.id)
                                              .Select(perm => new PermissionByRoleViewModel {
                            id  = perm.permByRol_id,
                            rol = new RolViewModel {
                                id = perm.rol_id, name = perm.roles.rol_name
                            }
                        })
                                              .ToList();

                        var permByMod = new List <PermissionByModuleViewModel>();
                        Dictionary <ModuleViewModel, PermissionViewModel> dicPermission = new Dictionary <ModuleViewModel, PermissionViewModel>();


                        foreach (var pbm in permissionByRol)
                        {
                            var permModule = db.permissionByRole.Where(p => p.permByRol_id == pbm.id)
                                             .Select(
                                p => new PermissionByModuleViewModel
                            {
                                id     = p.permByMdl_id,
                                module = new ModuleViewModel {
                                    id = p.permissionByModule.mdl_id, name = p.permissionByModule.modules.mdl_name
                                }
                            }
                                ).FirstOrDefault();

                            var permission = db.permissionByModule.Where(p => p.permByMdl_id == permModule.id)
                                             .Select(p => new PermissionViewModel
                            {
                                id          = p.perm_id,
                                name        = p.permission.perm_name,
                                description = p.permission.perm_description
                            }).FirstOrDefault();

                            dicPermission.Add(permModule.module, permission);
                        }


                        var lsModules = db.modules.Select(m => new ModuleViewModel {
                            id = m.mdl_id, name = m.mdl_name
                        }).ToList();

                        List <PermissionByModuleViewModel> lsPermByMod = new List <PermissionByModuleViewModel>();

                        foreach (var module in lsModules)
                        {
                            PermissionByModuleViewModel pXm = new PermissionByModuleViewModel();
                            pXm.lsPermission = new List <PermissionViewModel>();

                            var lsPermission = from p in dicPermission
                                               where p.Key.id == module.id
                                               select new PermissionViewModel {
                                id = p.Value.id, name = p.Value.name, description = p.Value.description
                            };

                            pXm.module = module;

                            foreach (var perm in lsPermission)
                            {
                                pXm.lsPermission.Add(perm);
                            }

                            lsPermByMod.Add(pXm);
                        }

                        user.rol.permissionByModule = lsPermByMod;

                        resp.response = true;
                        resp.message  = "Bienvenido " + user.name + " " + user.lastName;
                        resp.user     = user;
                    }
                    else
                    {
                        resp.response = false;
                        resp.message  = "Usuario o contraseña inválidos";
                    }
                }

                return(Ok(resp));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult GetPermissionByRol(int rol_id)
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsPermissionByModule = new List <PermissionByModuleViewModel>();

                    var lsPermissionByRol = db.permissionByRole.Where(perm => perm.rol_id == rol_id)
                                            .Select(
                        perm => new PermissionByModuleViewModel
                    {
                        id = perm.permByMdl_id
                    }
                        ).ToList();

                    Dictionary <ModuleViewModel, PermissionViewModel> dicPermission = new Dictionary <ModuleViewModel, PermissionViewModel>();

                    foreach (var perByMod in lsPermissionByRol)
                    {
                        var module = db.permissionByModule.Where(p => p.permByMdl_id == perByMod.id)
                                     .Select(p => new ModuleViewModel {
                            id = p.mdl_id, name = p.modules.mdl_name
                        })
                                     .FirstOrDefault();

                        var permission = db.permissionByModule.Where(p => p.permByMdl_id == perByMod.id)
                                         .Select(p => new PermissionViewModel
                        {
                            id          = p.perm_id,
                            name        = p.permission.perm_name,
                            description = p.permission.perm_description
                        })
                                         .FirstOrDefault();

                        dicPermission.Add(module, permission);
                    }



                    var lsModules = db.modules.Select(mdl => new ModuleViewModel {
                        id = mdl.mdl_id, name = mdl.mdl_name
                    })
                                    .ToList();



                    foreach (ModuleViewModel module in lsModules)
                    {
                        var lsPermission = from p in dicPermission
                                           where p.Key.id == module.id
                                           select new PermissionViewModel {
                            id = p.Value.id, name = p.Value.name, description = p.Value.description
                        };


                        PermissionByModuleViewModel prm = new PermissionByModuleViewModel();
                        prm.module       = module;
                        prm.lsPermission = new List <PermissionViewModel>();
                        foreach (var perm in lsPermission)
                        {
                            prm.lsPermission.Add(perm);
                        }

                        lsPermissionByModule.Add(prm);
                    }

                    return(Ok(lsPermissionByModule));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult GetAllRequest()
        {
            try
            {
                using (BD_DWHEntities db = new BD_DWHEntities())
                {
                    var lsRequest = db.Request.Where(r => r.rqt_state == true)
                                    .Select(r => new RequestViewModel
                    {
                        id     = r.rqt_id,
                        client = new ClientViewModel
                        {
                            document       = r.Client.cli_document,
                            kindOfDocument = new KindOfDocumentViewModel
                            {
                                id          = r.Client.kindOfDocument.kod_id,
                                description = r.Client.kindOfDocument.kod_description
                            },
                            name      = r.Client.cli_name,
                            lastName  = r.Client.cli_lastName,
                            cellPhone = r.Client.cli_cellPhone,
                            email     = r.Client.cli_email,
                            city      = new CityViewModel
                            {
                                id           = r.Client.Cities.cty_id,
                                name         = r.Client.Cities.cty_name,
                                departmentId = r.Client.Cities.dpt_id
                            },
                            economicActivity = new EconomicActivityViewModel
                            {
                                id          = r.Client.EconomicActivity.ea_id,
                                description = r.Client.EconomicActivity.ea_description
                            },
                            canal = new CanalViewModel
                            {
                                id          = r.Client.Canal.cnl_id,
                                description = r.Client.Canal.cnl_description
                            }
                        },
                        probability = new ProbabilityViewModel {
                            id = r.probability.prb_id, description = r.probability.prb_description
                        },
                        parentState = new StateViewModel {
                            id = r.states.sta_id, description = r.states.sta_description
                        },
                        childState = new StateViewModel {
                            id = r.states1.sta_id, description = r.states1.sta_description
                        },
                        user = new UserViewModel {
                            document = r.users.usu_document, name = r.users.usu_name, lastName = r.users.usu_lastName
                        },
                        contact = new ContactViewModel {
                            id = r.Contact.cnt_id, name = r.Contact.cnt_name, lastName = r.Contact.cnt_lastName
                        },
                        initialDate      = r.rqt_firstVisitDate,
                        lastDate         = r.rqt_lastVisitDate,
                        registrationDate = r.rqt_registrationDate
                    }).OrderByDescending(r => r.registrationDate)
                                    .ToList();

                    foreach (var rqt in lsRequest)
                    {
                        var riskInformation = db.riskInformationByRequest.Where(ri => ri.rqt_id == rqt.id && ri.ribr_state == true).FirstOrDefault();

                        if (riskInformation.states != null)
                        {
                            var oState = new StateViewModel();
                            oState.id          = riskInformation.states.sta_id;
                            oState.description = riskInformation.states.sta_description;

                            rqt.riskInformation = new RiskInformationViewModel()
                            {
                                id              = riskInformation.ribr_id,
                                riskState       = oState,
                                ammountApproved = long.Parse(riskInformation.ribr_ammountApproved.ToString()),
                                datefiling      = riskInformation.ribr_dateFiling
                            };
                        }



                        var operationalInformation = db.operationalInformationByRequest.Where(oi => oi.rqt_id == rqt.id && oi.oibr_state == true).FirstOrDefault();


                        rqt.operationalInformation = new OperationalInformationViewModel()
                        {
                            id = operationalInformation.oibr_id,
                            deliveredAmmount  = Decimal.Parse(operationalInformation.oibr_deliveredAmmount.ToString()),
                            deliveredVehicles = int.Parse(operationalInformation.oibr_deliveredVehicles.ToString()),
                            deliveredDate     = operationalInformation.oibr_deliveredDate,
                            legalizationDate  = operationalInformation.oibr_legalizationDate
                        };



                        var branch = db.branch.Where(br => br.cli_document == rqt.client.document).FirstOrDefault();

                        var lsContactsByClient = db.Contact.Where(cnt => cnt.bra_id == branch.bra_id)
                                                 .Select(cnt => new ContactViewModel
                        {
                            id        = cnt.cnt_id,
                            name      = cnt.cnt_name,
                            lastName  = cnt.cnt_lastName,
                            phone     = cnt.cnt_phone,
                            cellPhone = cnt.cnt_cellPhone,
                            email     = cnt.cnt_email,
                            jobTitle  = new JobTitleViewModel {
                                id = cnt.JobTitlesClient.jtcl_id, description = cnt.JobTitlesClient.jtcl_description
                            },
                            adress = cnt.cnt_adress,
                            branch = new BranchViewModel {
                                id = cnt.branch.bra_id, name = cnt.branch.bra_name
                            }
                        }).ToList();


                        rqt.client.lsContacts = lsContactsByClient;
                    }

                    return(Ok(lsRequest));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }