Exemplo n.º 1
0
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="categoriesSelected">categoriesSelected</param>
        /// <param name="companyId">companyId</param>
        public void Save(ArrayList categoriesSelected, int companyId)
        {
            UnitsAddTDS unitsAddChanges = (UnitsAddTDS)Data.GetChanges();

            if (unitsAddChanges.UnitsAddNew.Rows.Count > 0)
            {
                foreach (UnitsAddTDS.UnitsAddNewRow row in (UnitsAddTDS.UnitsAddNewDataTable)unitsAddChanges.UnitsAddNew)
                {
                    string type = ""; if (!row.IsTypeNull()) type = row.Type;
                    string code = row.Code;
                    string description = ""; if (!row.IsDescriptionNull()) description = row.Description;
                    string vin = ""; if (!row.IsVINNull()) vin = row.VIN;
                    string manufacturer = ""; if (!row.IsManufacturerNull()) manufacturer = row.Manufacturer;
                    string model = ""; if (!row.IsModelNull()) model = row.Model;
                    string year_ = ""; if (!row.IsYear_Null()) year_ = row.Year_;
                    bool isTowable = row.IsTowable;
                    Int64? licenseCountry = null; if (!row.IsLicenseCountryNull()) licenseCountry = row.LicenseCountry;
                    Int64? licenseState = null; if (!row.IsLicenseStateNull()) licenseState = row.LicenseState;
                    string licensePlateNumber = ""; if (!row.IsLicensePlateNumberNull()) licensePlateNumber = row.LicensePlateNumber;
                    int companyLevelId = row.CompanyLevelID;
                    string apportionedTagNumber = ""; if (!row.IsApportionedTagNumberNull()) apportionedTagNumber = row.ApportionedTagNumber;

                    string categories = "";

                    if (categoriesSelected.Count > 0)
                    {
                        foreach (int categoryId in categoriesSelected)
                        {
                            CategoryGateway categoryGateway = new CategoryGateway();
                            categoryGateway.LoadByCategoryId(categoryId, companyId);
                            categories = categories + categoryGateway.GetName(categoryId) + ", ";
                        }

                        if (categories.Length > 2)
                        {
                            categories = categories.Substring(0, categories.Length - 2);
                        }
                    }

                    Units units = new Units(null);
                    int unitId = units.InsertDirect(code, description, vin, manufacturer, model, year_, isTowable, companyLevelId, null, null, "", "", null, null, "", "", null, null, "", "Active", type, false, companyId, "", categories, "", "", null, null, null, null);

                    // ... Insert vehicle info
                    if (type == "Vehicle")
                    {
                        new UnitsVehicle(null).InsertDirect(unitId, licenseCountry, licenseState, licensePlateNumber, apportionedTagNumber, "", "", "", "", "", "", "", false, false, false, companyId);
                    }

                    // Save UnitCategory
                    UpdateUnitCategory(unitId, companyId, categoriesSelected);

                    // Save Checklist
                    UnitsChecklistRulesTemp unitChecklistRulesTemp = new UnitsChecklistRulesTemp(Data);
                    unitChecklistRulesTemp.Save(unitId, companyId);
                }
            }
        }