public ActionResult EditBuildingUnits(UpdateBuildingUnitsInput Model)
        {
            var BuildingUnit = new UpdateBuildingUnitsInput();

            BuildingUnit.Id                    = Model.Id;
            BuildingUnit.BuildingId            = Model.BuildingId;
            BuildingUnit.ResidentName          = Model.ResidentName;
            BuildingUnit.ResidenceStatus       = Model.ResidenceStatus;
            BuildingUnit.NumberOfFamilyMembers = Model.NumberOfFamilyMembers;
            BuildingUnit.Floor                 = Model.Floor;
            var unitContents = Request["UnitContentsMultiSelect"];

            string[] unitContentsSplited          = unitContents.Split(',');
            byte[]   unitContentsSplitedByteArray = new byte[unitContentsSplited.Length];
            for (var i = 0; i < unitContentsSplited.Length; i++)
            {
                unitContentsSplitedByteArray[i] = Convert.ToByte(unitContentsSplited[i]);
            }

            BuildingUnit.UnitContentsIds = unitContentsSplitedByteArray;
            _buildingUnitsAppService.Update(BuildingUnit);
            //get list of building units
            var getAllBuildingUnits = _buildingUnitsAppService.getAllBuildingUnits();
            // get list of building unit contents
            var getAllBuldingUnitContnet = _buildingUnitContentsAppService.getAllBuildingUnitContents();
            var buildingUntisViewModel   = new BuildingUnitViewModel()
            {
                BuildingUnits        = getAllBuildingUnits,
                BuildingUnitContents = getAllBuldingUnitContnet
            };

            return(View("BuildingUnit", buildingUntisViewModel));
        }
Example #2
0
        public ActionResult UpdateApplication(UpdateApplicationsInput model)
        {
            var updateApplication = new UpdateApplicationsInput();

            updateApplication.buildingId     = Convert.ToInt32(Request["buildingnumber"]);
            updateApplication.buildingUnitId = Convert.ToInt32(Request["dropDownBuildingUnitApp"]);
            //==== get building and unit related to application for update ======
            //var buildingInput = new GetBuidlingsInput()
            //{
            //    Id = updateApplication.buildingId
            //};
            //var buildingUnitInput = new GetBuildingUnitsInput()
            //{
            //    Id = updateApplication.buildingUnitId
            //};

            // using task and async method
            // var buildingApp = _buildingsAppService.getBuildingsByIdAsync(buildingInput).Result;
            // var buildingApp = _buildingsAppService.getBuildingsById(buildingInput);
            // var buildingUnitApp = _buildingUnitsAppService.GetBuildingUnitsById(buildingUnitInput);
            // buildingUnitApp.BuildingId = updateApplication.buildingId;
            //  buildingUnitApp.ResidenceStatus= Request["residentstatus"];


            // copy object getBuildingUnitInput to updateBuildingUnitInput
            var updateBuildingUnitInput = new UpdateBuildingUnitsInput();
            //{
            //    BuildingId = buildingUnitApp.BuildingId,
            //    ResidentName=buildingUnitApp.ResidentName,
            //    ResidenceStatus=buildingUnitApp.ResidenceStatus,
            //    NumberOfFamilyMembers=buildingUnitApp.NumberOfFamilyMembers,
            //    Floor=buildingUnitApp.Floor,
            //    UnitContentsIds=buildingUnitApp.UnitContentsIds
            //};
            //============================================
            // copy object from getBuildingOutput to updateBuildingInput
            var updateBuildingInput = new UpdateBuidlingsInput();
            //{
            //   Id = buildingApp.Id,
            //   buildingID = buildingApp.buildingID,
            //   numOfBuildingUnits = buildingApp.numOfBuildingUnits,
            //   numOfFloors = buildingApp.numOfFloors,
            //   streetName = buildingApp.streetName,
            //   buildingNo =buildingApp.buildingNo,
            //   neighborhoodID= buildingApp.neighborhoodID,
            //   buildingTypeID=buildingApp.buildingTypeID,
            //   GISMAP=buildingApp.GISMAP,
            //   houshProperty=buildingApp.houshProperty,
            //   houshName= buildingApp.houshName,
            //   X=buildingApp.X,
            //   Y=buildingApp.Y,
            //   buildingName=buildingApp.buildingName,
            //   isInHoush =buildingApp.isInHoush,
            //   buildingUsesID=buildingApp.buildingUsesID

            //};



            //======================================================
            // connect to database using ADO.net to retreive building unit details ========
            string construnit = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (SqlConnection con = new SqlConnection(construnit))
            {
                string query = "SELECT Id," +
                               " BuildingId," +
                               "ResidentName," +
                               "ResidenceStatus," +
                               "NumberOfFamilyMembers," +
                               "Floor," +
                               "UnitContentsIds" +
                               " FROM BuildingUnits Where Id=" + updateApplication.buildingUnitId;
                using (SqlCommand cmd = new SqlCommand(query))
                {
                    cmd.Connection = con;
                    con.Open();
                    //cmd.Parameters.Add(new SqlParameter("@Id", paramValue));
                    SqlDataReader reader = cmd.ExecuteReader();
                    // reader.GetString(1)
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            updateBuildingUnitInput.Id                    = reader.GetInt32(0);
                            updateBuildingUnitInput.BuildingId            = reader.GetInt32(1);
                            updateBuildingUnitInput.ResidentName          = reader.GetString(2);
                            updateBuildingUnitInput.ResidenceStatus       = reader.GetString(3);
                            updateBuildingUnitInput.NumberOfFamilyMembers = reader.GetInt32(4);
                            updateBuildingUnitInput.Floor                 = reader.GetString(5);
                            updateBuildingUnitInput.UnitContentsIds       = (byte[])reader.GetValue(6);
                        }
                    }
                    else
                    {
                        throw new UserFriendlyException("No rows found.");
                    }
                    reader.Close();
                    con.Close();
                }
            }
            // read any changes made on building unit through the form .
            updateBuildingUnitInput.ResidenceStatus = Request["residentstatus"];
            //======================================================
            // connect to database using ADO.net to retreive building details ========
            string constr = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (SqlConnection con = new SqlConnection(constr))
            {
                string query = "SELECT buildingID," +
                               " Id," +
                               "numOfBuildingUnits," +
                               "numOfFloors," +
                               "streetName," +
                               "buildingNo," +
                               "neighborhoodID," +
                               "buildingTypeID," +
                               "GISMAP," +
                               "houshProperty," +
                               "houshName," +
                               "X," +
                               "Y," +
                               "buildingName," +
                               "isInHoush," +
                               "buildingUsesID" +
                               " FROM Buildings Where Id=" + updateApplication.buildingId;
                using (SqlCommand cmd = new SqlCommand(query))
                {
                    cmd.Connection = con;
                    con.Open();
                    //cmd.Parameters.Add(new SqlParameter("@Id", paramValue));
                    SqlDataReader reader = cmd.ExecuteReader();
                    // reader.GetString(1)
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            updateBuildingInput.buildingID         = reader.GetInt32(0);
                            updateBuildingInput.Id                 = reader.GetInt32(1);
                            updateBuildingInput.numOfBuildingUnits = reader.GetInt32(2);
                            updateBuildingInput.numOfFloors        = reader.GetInt32(3);
                            updateBuildingInput.streetName         = reader.GetString(4);
                            updateBuildingInput.buildingNo         = reader.GetInt32(5);
                            updateBuildingInput.neighborhoodID     = reader.GetInt32(6);
                            updateBuildingInput.buildingTypeID     = reader.GetInt32(7);
                            updateBuildingInput.GISMAP             = reader.GetString(8);
                            updateBuildingInput.houshProperty      = reader.GetByte(9);
                            updateBuildingInput.houshName          = reader.GetString(10);
                            updateBuildingInput.X              = reader.GetDouble(11);
                            updateBuildingInput.Y              = reader.GetDouble(12);
                            updateBuildingInput.buildingName   = reader.GetString(13);
                            updateBuildingInput.isInHoush      = reader.GetBoolean(14);
                            updateBuildingInput.buildingUsesID = reader.GetInt32(15);
                        }
                    }
                    else
                    {
                        throw new UserFriendlyException("No rows found.");
                    }
                    reader.Close();
                    con.Close();
                }
            }
            // read any changes made on building through the form
            updateBuildingInput.streetName = Request["buildingaddress"];
            updateBuildingInput.isInHoush  = Convert.ToBoolean(Request["buildingOutput.isInHoush"]);
            updateBuildingInput.houshName  = Request["HoushName"];
            //===================================================================================
            //=====================================================
            updateApplication.Id           = Convert.ToInt32(Request["applicationId"]);
            updateApplication.fullName     = model.fullName;
            updateApplication.phoneNumber1 = model.phoneNumber1;
            updateApplication.phoneNumber2 = model.phoneNumber2;
            updateApplication.isThereFundingOrPreviousRestoration = model.isThereFundingOrPreviousRestoration;
            updateApplication.isThereInterestedRepairingEntity    = model.isThereInterestedRepairingEntity;
            updateApplication.housingSince = model.housingSince;
            updateApplication.previousRestorationSource     = model.previousRestorationSource;
            updateApplication.interestedRepairingEntityName = model.interestedRepairingEntityName;
            updateApplication.PropertyOwnerShipId           = Convert.ToInt32(Request["PropertyOwnerShip"]);
            updateApplication.otherOwnershipType            = model.otherOwnershipType;
            updateApplication.interventionTypeId            = Convert.ToInt32(Request["interventionTypeName"]);
            updateApplication.otherRestorationType          = model.otherRestorationType;
            updateApplication.propertyStatusDescription     = model.propertyStatusDescription;
            updateApplication.requiredRestoration           = model.requiredRestoration;
            updateApplication.buildingId     = Convert.ToInt32(Request["buildingnumber"]);
            updateApplication.buildingUnitId = Convert.ToInt32(Request["dropDownBuildingUnitApp"]);
            // ==== get of restoration types which it is multi select drop down list ======
            var restorationTypes = Request["example-getting-started"];

            string[] restorationTypesSplited = restorationTypes.Split(',');
            byte[]   restorationTypesArray   = new byte[restorationTypesSplited.Length];
            for (var i = 0; i < restorationTypesArray.Length; i++)
            {
                restorationTypesArray[i] = Convert.ToByte(restorationTypesSplited[i]);
            }

            updateApplication.restorationTypeIds = restorationTypesArray;

            // ====== end of RestorationTypes


            // _buildingsAppService.updateAsync(updateBuildingInput);
            _buildingsAppService.update(updateBuildingInput);
            _applicationsAppService.Update(updateApplication);
            _buildingUnitsAppService.Update(updateBuildingUnitInput);

            // ==== get list of applications ==============
            var applicationsUpdate    = _applicationsAppService.getAllApplications();
            var applicationsViewModel = new ApplicationsViewModel()
            {
                Applications = applicationsUpdate
            };

            return(View("Applications", applicationsViewModel));
        }