Esempio n. 1
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------

        public TreeDetail CreateProject_Organism(int varas, decimal height, decimal lat, decimal lon, int[] daps, ActionProposed actionProposed, Condition condition, string commentary, Organism organism, Project project, Eisk.BusinessEntities.User user)
        {
            Project_Organisms project_Organism = new Project_Organisms();

            project_Organism.CreatorUserID = user.UserID;
            project_Organism.CreatedDate   = DateTime.Now;
            project_Organism.EditorUserID  = user.UserID;
            project_Organism.EditedDate    = DateTime.Now;

            project_Organism.OrganismID = organism.OrganismID;
            project_Organism.OrganismReference.EntityKey = organism.EntityKey;

            project_Organism.ProjectID = project.ProjectID;
            project_Organism.ProjectReference.EntityKey = project.EntityKey;

            int project_OrganismID = new Project_OrganismsBLL().CreateNewProject_Organisms(project_Organism);

            TreeDetail treeDetail = new TreeDetail();

            if (varas != 0) // Is Cepa
            {
                treeDetail.Dap         = 0;
                treeDetail.Dap_Counter = 0;
            }
            else if (daps.Length == 1) // Solo un Dap
            {
                treeDetail.Dap         = daps[0];
                treeDetail.Dap_Counter = 1;
            }
            else // Mas de un Dap
            {
                double dapTotal = 0;
                foreach (int dap in daps)
                {
                    dapTotal += dap;
                }
                treeDetail.Dap         = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Length)) * 100) / 100);
                treeDetail.Dap_Counter = daps.Length;
            }

            treeDetail.Varas = varas;

            treeDetail.Height     = height;
            treeDetail.Commentary = commentary;

            List <Project_Organisms> project_Organisms = new Project_OrganismsBLL().GetProject_OrganismsByProjectID(project.ProjectID);

            Dictionary <string, object> anewpointObj = JavaScriptHelper.ConvertToStatePlane(lon.ToString(), lat.ToString());

            treeDetail.Number = project_Organisms.Count;
            treeDetail.Y      = Convert.ToDecimal(anewpointObj["y"]);
            treeDetail.X      = Convert.ToDecimal(anewpointObj["x"]);
            treeDetail.Lat    = Convert.ToDecimal(lat);
            treeDetail.Lon    = Convert.ToDecimal(lon);

            treeDetail.CreatedDate   = DateTime.Now;
            treeDetail.CreatorUserID = user.UserID;
            treeDetail.EditedDate    = DateTime.Now;
            treeDetail.EditorUserID  = user.UserID;


            treeDetail.ActionProposedID = actionProposed.ActionProposedID;
            treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey;

            treeDetail.ConditionID = condition.ConditionID;
            treeDetail.ConditionReference.EntityKey = condition.EntityKey;

            treeDetail.ProjectOrganismID = project_Organism.ProjectOrganismID;
            treeDetail.Project_OrganismsReference.EntityKey = project_Organism.EntityKey;

            int treeDetailID = new TreeDetailBLL().CreateNewTreeDetail(treeDetail);

            foreach (decimal dapDecimal in daps)
            {
                Dap dap = new Dap();
                dap.DapValue      = dapDecimal;
                dap.TreeDetailsID = treeDetailID;
                dap.TreeDetailReference.EntityKey = treeDetail.EntityKey;

                new DapBLL().CreateNewDap(dap);
            }
            return(treeDetail);
        }