Example #1
0
 private async void HeaderAsync(Model.InspectionDetailTable inspectionRequestDTO, int MaxHeaderCode, Boolean New)
 {
     inspectionRequestDTO.Id = MaxHeaderCode;
     if (New)
     {
         inspectionRequestDTO.CreatedAt = DateTime.Now;
         inspectionRequestDTO.NewEntry  = true;
         await InitData.DetailsRepo.InsertItemAsync(inspectionRequestDTO);
     }
     else
     {
         inspectionRequestDTO.ModifiedAt = DateTime.Now;
         inspectionRequestDTO.Updated    = true;
         await InitData.DetailsRepo.UpdateItemAsync(inspectionRequestDTO);
     }
 }
Example #2
0
        public async void AddNew_Command()
        {
            if (SampleSize == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert ", "Please Enter Sample Size!", "ok");
            }
            else if (SelectedSize == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please select Size Description!", "ok");
            }
            else if (SelectedOppening == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please select Oppening!", "ok");
            }
            else if (SelectedPackageCondition == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please select Package Condition!", "ok");
            }
            else if (Weight == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Weight!", "ok");
            }
            else if (PhysicalCount == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Physical Count!", "ok");
            }
            else if (Temperature == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Temperature!", "ok");
            }
            else if (Brix == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Brix!", "ok");
            }
            else if (Firmness == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Firmness!", "ok");
            }
            else
            {
                try
                {
                    UserDialogs.Instance.ShowLoading("Loading...");
                    RememberMe.Set("isSyncDatabse", true);
                    await Xamarin.Forms.Application.Current.SavePropertiesAsync();

                    InspectionDetailsRequestDTO inspectionRequestDTO = new InspectionDetailsRequestDTO()
                    {
                        Id = InspectionDetailsID,
                        InspectionHeaderId = InspectionHeaderID,
                        SizeId             = (int)SelectedSize.Id,
                        //SizeId = 3,
                        SampleSize         = SampleSize,
                        Weight             = Weight,
                        PhysicalCount      = PhysicalCount,
                        OpeningApperenceId = (int)SelectedOppening.Id,
                        //OpeningApperenceId = 2,
                        Temperature        = Temperature,
                        Brix               = Brix,
                        Firmness           = Firmness,
                        SkinDamage         = SkinDamage,
                        Color              = Color,
                        PackageConditionId = (int)SelectedPackageCondition.Id,
                        //PackageConditionId = 1,
                        Comment      = Comment,
                        QualityScore = QualityScore
                    };
                    Model.InspectionDetailTable inspectionDetailTable = new Model.InspectionDetailTable
                    {
                        Id = 0,
                        InspectionHeaderId = inspectionRequestDTO.InspectionHeaderId,
                        SizeId             = inspectionRequestDTO.SizeId,
                        SampleSize         = inspectionRequestDTO.SampleSize,
                        Weight             = inspectionRequestDTO.Weight,
                        PhysicalCount      = inspectionRequestDTO.PhysicalCount,
                        OpeningApperenceId = inspectionRequestDTO.OpeningApperenceId,
                        Temperature        = inspectionRequestDTO.Temperature,
                        Brix               = inspectionRequestDTO.Brix,
                        Firmness           = inspectionRequestDTO.Firmness,
                        SkinDamage         = inspectionRequestDTO.SkinDamage,
                        Color              = inspectionRequestDTO.Color,
                        PackageConditionId = inspectionRequestDTO.PackageConditionId,
                        Comment            = inspectionRequestDTO.Comment,
                        QualityScore       = inspectionRequestDTO.QualityScore,
                    };

                    if (ConfigurationCommon.App_Online)
                    {
                        var result = await webServiceManager.RegistrationInspectionDetailsAsync(inspectionRequestDTO).ConfigureAwait(true);;
                        if (result.IsSuccess && result.Data.StatusCode == 0)
                        {
                            if (InspectionDetailsID > 0)
                            {
                                HeaderAsync(inspectionDetailTable, result.Data.Id, false);
                            }
                            else
                            {
                                HeaderAsync(inspectionDetailTable, result.Data.Id, true);
                            }
                            // save data
                            await App.Current.MainPage.DisplayAlert("Alert", "Inspection Details has been Saved!", "ok");

                            if (DashBoardViewModel.CheckNewInspection)
                            {
                                await _navigationService.GoBackToRootAsync();
                            }
                            else
                            {
                                await _navigationService.GoBackAsync();
                            }
                        }
                        else
                        {
                            await App.Current.MainPage.DisplayAlert("Alert", result.Data.Status, "ok");
                        }
                    }
                    else
                    {
                        int MaxHeaderCode = 0;
                        if (InspectionDetailsID == 0)
                        {
                            var data = await InitData.HeaderRepo.GetMaxCode(x => x.Id, false);

                            MaxHeaderCode = (int)data.Id + 1;
                        }
                        else
                        {
                            MaxHeaderCode = InspectionDetailsID;
                        }
                        if (InspectionDetailsID > 0)
                        {
                            inspectionDetailTable.ModifiedAt = DateTime.Now;
                            inspectionDetailTable.Updated    = true;
                            HeaderAsync(inspectionDetailTable, MaxHeaderCode, false);

                            await App.Current.MainPage.DisplayAlert("Alert", "Inspection Details has been Saved!", "ok");

                            if (DashBoardViewModel.CheckNewInspection)
                            {
                                await _navigationService.GoBackAsync();

                                await _navigationService.GoBackAsync();

                                //await _navigationService.GoBackToRootAsync();
                            }
                            else
                            {
                                await _navigationService.GoBackAsync();
                            }
                        }
                        else
                        {
                            inspectionDetailTable.CreatedAt = DateTime.Now;
                            inspectionDetailTable.NewEntry  = true;
                            HeaderAsync(inspectionDetailTable, MaxHeaderCode, true);
                            await App.Current.MainPage.DisplayAlert("Alert", "Inspection Details has been Saved!", "ok");

                            if (DashBoardViewModel.CheckNewInspection)
                            {
                                await _navigationService.GoBackToRootAsync();
                            }
                            else
                            {
                                await _navigationService.GoBackAsync();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    UserDialogs.Instance.HideLoading();
                    throw ex;
                }
                finally
                {
                    UserDialogs.Instance.HideLoading();
                }
            }
        }