// GET: /Organizations/Edit/1
        public ActionResult Edit(int id)
        {
            var asset = _assetEntryManager.Get(id);

            if (asset == null)
            {
                return(HttpNotFound());
            }

            var assetEntryVm = new AssetEntryViewModel()
            {
                Id                 = asset.Id,
                OrganizationId     = asset.OrganizationId,
                BranchId           = asset.BranchId,
                AssetLocationId    = asset.AssetLocationId,
                AssetTypeId        = asset.AssetTypeId,
                AssetGroupId       = asset.AssetGroupId,
                AssetManufacurerId = asset.AssetManufacurerId,
                AssetModelId       = asset.AssetModelId,
                AssetId            = asset.AssetId,
                Name               = asset.Name,
                SerialNo           = asset.SerialNo,
                Brand              = asset.Brand,
                Status             = asset.Status,

                // dropdown

                Organizations  = _organizationManager.GetAll(),
                Branchs        = _branchManager.GetBranchByOrgId(asset.OrganizationId),
                AssetLocations = _assetLocationManager.GetAssetLocationByBranchId(asset.BranchId),

                AssetTypes        = _assetTypeManager.GetAll(),
                AssetGroups       = _assetGroupManager.GetAssetGroupsByType(asset.AssetTypeId),
                AssetManufacurers = _assetManufacturerManager.GetManufacurersByGroupId(asset.AssetGroupId),
                AssetModels       = _assetModelManager.GetAllModelByManufacturerId(asset.AssetManufacurerId),
                Statuses          = new List <Status>()
                {
                    new Status()
                    {
                        Id = true, Name = "Active"
                    },
                    new Status()
                    {
                        Id = false, Name = "Inactive"
                    }
                }
            };

            AssetTableId = asset.Id;
            return(View("AssetEditForm", assetEntryVm));
        }
        public ActionResult New()
        {
            var assetEntryVm = new AssetEntryViewModel()
            {
                Organizations = _organizationManager.GetAll(),
                Branchs       = new List <Branch>()
                {
                },
                AssetLocations = new List <AssetLocation>()
                {
                },

                AssetTypes  = _assetTypeManager.GetAll(),
                AssetGroups = new List <AssetGroup>()
                {
                },
                AssetManufacurers = new List <AssetManufacurer>()
                {
                },
                AssetModels = new List <AssetModel>()
                {
                },
                Statuses = new List <Status>()
                {
                    new Status()
                    {
                        Id = true, Name = "Active"
                    },
                    new Status()
                    {
                        Id = false, Name = "Inactive"
                    }
                }
            };

            return(View("AssetEntryForm", assetEntryVm));
        }
        public ActionResult Save(AssetEntryViewModel assetEntyVm)
        {
            var assetEntryVmDropdown = new AssetEntryViewModel()
            {
                Organizations  = _organizationManager.GetAll(),
                Branchs        = _branchManager.GetBranchByOrgId(assetEntyVm.OrganizationId),
                AssetLocations = _assetLocationManager.GetAssetLocationByBranchId(assetEntyVm.BranchId),

                AssetTypes        = _assetTypeManager.GetAll(),
                AssetGroups       = _assetGroupManager.GetAssetGroupsByType(assetEntyVm.AssetTypeId),
                AssetManufacurers = _assetManufacturerManager.GetManufacurersByGroupId(assetEntyVm.AssetGroupId),
                AssetModels       = _assetModelManager.GetAllModelByManufacturerId(assetEntyVm.AssetManufacurerId),
                Statuses          = new List <Status>()
                {
                    new Status()
                    {
                        Id = true, Name = "Active"
                    },
                    new Status()
                    {
                        Id = false, Name = "Inactive"
                    }
                }
            };

            ModelState.Remove("Id");

            if (ModelState.IsValid)
            {
                if (assetEntyVm.Id == 0)
                {
                    var assetEntry = new AssetEntry()
                    {
                        OrganizationId     = assetEntyVm.OrganizationId,
                        BranchId           = assetEntyVm.BranchId,
                        AssetLocationId    = assetEntyVm.AssetLocationId,
                        AssetTypeId        = assetEntyVm.AssetTypeId,
                        AssetGroupId       = assetEntyVm.AssetGroupId,
                        AssetManufacurerId = assetEntyVm.AssetManufacurerId,
                        AssetModelId       = assetEntyVm.AssetModelId,
                        AssetId            = assetEntyVm.AssetId,
                        Name     = assetEntyVm.Name,
                        SerialNo = assetEntyVm.SerialNo,
                        Brand    = assetEntyVm.Brand,
                        Status   = assetEntyVm.Status
                    };
                    _assetEntryManager.Add(assetEntry);

                    ModelState.Clear();

                    // Edit Page
                    assetEntryVmDropdown.OrganizationId     = assetEntyVm.OrganizationId;
                    assetEntryVmDropdown.BranchId           = assetEntyVm.BranchId;
                    assetEntryVmDropdown.AssetLocationId    = assetEntyVm.AssetLocationId;
                    assetEntryVmDropdown.AssetTypeId        = assetEntyVm.AssetTypeId;
                    assetEntryVmDropdown.AssetGroupId       = assetEntyVm.AssetGroupId;
                    assetEntryVmDropdown.AssetManufacurerId = assetEntyVm.AssetManufacurerId;
                    assetEntryVmDropdown.AssetModelId       = assetEntyVm.AssetModelId;
                    assetEntryVmDropdown.AssetId            = assetEntyVm.AssetId;
                    assetEntryVmDropdown.Name     = assetEntyVm.Name;
                    assetEntryVmDropdown.SerialNo = assetEntyVm.SerialNo;
                    assetEntryVmDropdown.Brand    = assetEntyVm.Brand;
                    assetEntryVmDropdown.Status   = assetEntyVm.Status;

                    return(View("AssetEditForm", assetEntryVmDropdown));
                }
            }

            return(View("AssetEntryForm", assetEntryVmDropdown));
        }