Example #1
0
        private async Task LoadPickers()
        {
            pAssetGroup.Items.Clear();
            pDepartment.Items.Clear();
            pAccountable.Items.Clear();
            pLocation.Items.Clear();
            var client             = new WebApi();
            var assetGroupResponse = await client.PostAsync(null, "AssetGroups");

            _assetGroupList = JsonConvert.DeserializeObject <List <AssetGroup> >(assetGroupResponse);
            foreach (var item in _assetGroupList)
            {
                pAssetGroup.Items.Add(item.Name);
            }

            var departmentResponse = await client.PostAsync(null, "Departments");

            _departmentList = JsonConvert.DeserializeObject <List <Department> >(departmentResponse);
            foreach (var item in _departmentList)
            {
                pDepartment.Items.Add(item.Name);
            }

            var employeeResponse = await client.PostAsync(null, "Employees");

            _accountableList = JsonConvert.DeserializeObject <List <Employee> >(employeeResponse);
            foreach (var item in _accountableList)
            {
                pAccountable.Items.Add(item.FirstName + " " + item.LastName);
            }

            var departmentLocationResponse = await client.PostAsync(null, "DepartmentLocations");

            _departmentLocationList = JsonConvert.DeserializeObject <List <DepartmentLocation> >(departmentLocationResponse);

            var locationResponse = await client.PostAsync(null, "Locations");

            _locationList = JsonConvert.DeserializeObject <List <Location> >(locationResponse);
        }
Example #2
0
        private async Task LoadPickers()
        {
            pAssetGroup.Items.Clear();
            pDepartment.Items.Clear();
            pAssetGroup.Items.Add("No Filter");
            pDepartment.Items.Add("No Filter");
            var client             = new WebApi();
            var assetGroupResponse = await client.PostAsync(null, "AssetGroups");

            _assetGroupList = JsonConvert.DeserializeObject <List <AssetGroup> >(assetGroupResponse);
            foreach (var item in _assetGroupList)
            {
                pAssetGroup.Items.Add(item.Name);
            }

            var departmentResponse = await client.PostAsync(null, "Departments");

            _departmentList = JsonConvert.DeserializeObject <List <Department> >(departmentResponse);
            foreach (var item in _departmentList)
            {
                pDepartment.Items.Add(item.Name);
            }
        }
Example #3
0
        private async void btnSubmit_Clicked(object sender, EventArgs e)
        {
            var client         = new WebApi();
            var getAccountable = (from x in _accountableList
                                  where pAccountable.SelectedItem.ToString().Contains(x.FirstName + " " + x.LastName)
                                  select x.ID).FirstOrDefault();
            var getAssetGroupID = (from x in _assetGroupList
                                   where x.Name == pAssetGroup.SelectedItem.ToString()
                                   select x.ID).FirstOrDefault();

            var getDepartmentID = (from x in _departmentList
                                   where x.Name == pDepartment.SelectedItem.ToString()
                                   select x.ID).FirstOrDefault();

            var getLocationID = (from x in _locationList
                                 where x.Name == pLocation.SelectedItem.ToString()
                                 select x.ID).FirstOrDefault();
            var getDepartmentLocationID = (from x in _departmentLocationList
                                           where x.LocationID == getLocationID && x.DepartmentID == getDepartmentID
                                           where x.EndDate == null
                                           select x.ID).FirstOrDefault();

            if (_assetID != 0)
            {
                if (string.IsNullOrWhiteSpace(editorAssetDescription.Text))
                {
                    _asset.Description  = " ";
                    _asset.EmployeeID   = getAccountable;
                    _asset.WarrantyDate = dpWarranty.Date;
                }
                else
                {
                    _asset.Description  = editorAssetDescription.Text;
                    _asset.EmployeeID   = getAccountable;
                    _asset.WarrantyDate = dpWarranty.Date;
                }
                var response = await client.PostAsync(JsonConvert.SerializeObject(_asset), "Assets/Edit");

                if (response != "\"Successfully edited Asset!\"")
                {
                    await DisplayAlert("Submit", "An error occured while editing asset!", "Ok");
                }
                else
                {
                    await DisplayAlert("Submit", "Successfully edited Asset!", "Ok");

                    await Navigation.PopAsync();
                }
            }
            else
            {
                var newAsset = new Asset()
                {
                    AssetGroupID         = getAssetGroupID,
                    AssetName            = entryAssetName.Text,
                    AssetSN              = lblAssetSN.Text,
                    DepartmentLocationID = getDepartmentLocationID,
                    EmployeeID           = getAccountable,
                    WarrantyDate         = dpWarranty.Date
                };
                if (string.IsNullOrWhiteSpace(editorAssetDescription.Text))
                {
                    newAsset.Description = " ";
                }
                else
                {
                    newAsset.Description = editorAssetDescription.Text;
                }
                var response = await client.PostAsync(JsonConvert.SerializeObject(newAsset), "Assets/Create");

                if (response != "\"Successfully created Asset!\"")
                {
                    if (response == "\"Asset already exist in location!\"")
                    {
                        await DisplayAlert("Submit", "Please change your Asset Name and or location!", "Ok");
                    }
                    else
                    {
                        await DisplayAlert("Submit", "An error occured while creating asset!", "Ok");
                    }
                }
                else
                {
                    await DisplayAlert("Submit", "Successfully created Asset!", "Ok");

                    await Navigation.PopAsync();
                }
            }
        }