Beispiel #1
0
        public Report_Project_Data GetProject(int id)
        {
            Report_Project_Data project = new Report_Project_Data();
            Project             pr;

            using (TeConstruyeEntities1 construyeEntities = new TeConstruyeEntities1())
            {
                try
                {
                    if (!this.existProject(id))
                    {
                        project = null;
                        return(project);
                    }
                    pr                = construyeEntities.Projects.Where(e => e.id == id).ToList().First();
                    project.id        = pr.id;
                    project.id_client = pr.id_client;
                    project.manager   = pr.manager;
                    project.name      = pr.name;
                    project.ubication = pr.ubication;


                    var        costos      = construyeEntities.usp_total_bills(id).First();
                    var        etapasList  = construyeEntities.Stages.Where(e => e.id_project == id).ToList();
                    List <int> idStageList = new List <int>();
                    for (int i = 0; i < etapasList.Count; ++i)
                    {
                        idStageList.Add(etapasList.ElementAt(i).id);
                    }

                    var        anotationsList  = construyeEntities.Anotations.Where(e => e.id_project == id).ToList();
                    List <int> idAnotationList = new List <int>();
                    for (int i = 0; i < anotationsList.Count; ++i)
                    {
                        idAnotationList.Add(anotationsList.ElementAt(i).id);
                    }

                    project.totalCost    = (int)costos.TotalReal;
                    project.totalBudget  = (int)costos.TotalPresupuesto;
                    project.idAnotations = idAnotationList;
                    project.idStages     = idStageList;

                    return(project);
                }
                catch (Exception E)
                {
                    project = null;
                    return(project);
                }
            }
        }
        public IHttpActionResult GetProject(int id)
        {
            if (!projectLogic.existProject(id))
            {
                //No se encontró el recurso code 404
                return(NotFound());
            }
            Report_Project_Data project = projectLogic.GetProject(id);

            if (project != null)
            {
                // ok code 200
                return(Ok(project));
            }
            else
            {
                //No se pudo crear el recurso por un error interno code 500
                return(InternalServerError());
            }
        }
Beispiel #3
0
        public List <Object> GetListProject()
        {
            List <Object> dataList = new List <object>();

            using (TeConstruyeEntities1 construyeEntities = new TeConstruyeEntities1())
            {
                try
                {
                    var projectList = construyeEntities.Projects.ToList();
                    int n           = projectList.Count;
                    if (n == 0)
                    {
                        dataList = null;
                        return(dataList);
                    }
                    else
                    {
                        for (int i = 0; i < projectList.Count; ++i)
                        {
                            Report_Project_Data project = new Report_Project_Data();
                            Project             pr;
                            pr                = projectList.ElementAt(i);
                            project.id        = pr.id;
                            project.id_client = pr.id_client;
                            project.manager   = pr.manager;
                            project.name      = pr.name;
                            project.ubication = pr.ubication;


                            var        costos      = construyeEntities.usp_total_bills(pr.id).First();
                            var        etapasList  = construyeEntities.Stages.Where(e => e.id_project == pr.id).ToList();
                            List <int> idStageList = new List <int>();
                            for (int j = 0; j < etapasList.Count; ++j)
                            {
                                idStageList.Add(etapasList.ElementAt(j).id);
                            }

                            var        anotationsList  = construyeEntities.Anotations.Where(e => e.id_project == pr.id).ToList();
                            List <int> idAnotationList = new List <int>();
                            for (int j = 0; j < anotationsList.Count; ++j)
                            {
                                idAnotationList.Add(anotationsList.ElementAt(j).id);
                            }

                            if (costos.TotalPresupuesto == null || costos.TotalReal == null)
                            {
                                project.totalCost    = 0;
                                project.totalBudget  = 0;
                                project.idAnotations = idAnotationList;
                                project.idStages     = idStageList;
                                dataList.Add(project);
                                continue;
                            }
                            project.totalCost    = (int)costos.TotalReal;
                            project.totalBudget  = (int)costos.TotalPresupuesto;
                            project.idAnotations = idAnotationList;
                            project.idStages     = idStageList;
                            dataList.Add(project);
                        }
                        return(dataList);
                    }
                }
                catch
                {
                    dataList = null;
                    return(dataList);
                }
            }
        }