Example #1
0
        private async void DeliveryButton_Clicked(object sender, EventArgs e)
        {
            CourierModel courier = CourierPicker.SelectedItem as CourierModel;

            if (DeliveryButton.Text.ToLower() == "završi" && PotencialDelivery != null)
            {
                if (await CheckDelivery(PotencialDelivery))
                {
                    try
                    {
                        PotencialDelivery.PaymentTypeID     = PaymentTypePicker.SelectedIndex + 1;
                        PotencialDelivery.DeliveryTypeID    = DeliverTypePicker.SelectedIndex + 1;
                        PotencialDelivery.CourierID         = courier.CourierID;
                        PotencialDelivery.StartAddress.Zone = Convert.ToInt32(ZoneStart.Value);
                        PotencialDelivery.EndAddress.Zone   = Convert.ToInt32(ZoneEnd.Value);
                        PotencialDelivery.CreateTime        = DateTime.Now;


                        if (await StartAddressCheck())
                        {
                            await DisplayAlert("Greska", "", "Potvrdi");
                        }

                        if (await EndAddressCheck())
                        {
                            await DisplayAlert("Greska", "", "Potvrdi");
                        }
                        DeliveryModel dtodel = PotencialDelivery;
                        dtodel.StartAddress = null;
                        dtodel.EndAddress   = null;

                        var PostDelivery = await deliveryService.CreateDelivery(dtodel);

                        if (PostDelivery != null)
                        {
                            await DisplayAlert("BaraBara", "Dostava je poslata kuriru", "Potvrdi.");

                            await Navigation.PopToRootAsync();
                        }
                        else
                        {
                            await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo.", "Potvrdi");
                        }
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo. " + Environment.NewLine + "Tekst greške : " + ex.Message, "Potvrdi");
                    }
                }
                else
                {
                    await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo.", "Potvrdi");
                }
            }
            else
            {
                await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo.", "Potvrdi");
            }
        }
Example #2
0
        private async void OrderDelivery_Clicked(object sender, EventArgs e)
        {
            bool done = false;

            try
            {
                #region Check start address

                #endregion
                #region Check end address

                #endregion
                #region Check Delivery
                if (delivery.DeliveryID > 0 && EditEnabled)
                {
                    DeliveryModel deliveryFromDB = await deliveryService.GetDeliveryByID(delivery.DeliveryID);

                    if (deliveryFromDB != null)
                    {
                        if (delivery.CompareTo(deliveryFromDB).ContainsValue(false))
                        {
                            await deliveryService.EditDelivery(delivery);
                            await DisplayAlert("Success", "Updated existing delivery", "Ok");

                            done = true;
                            #region UpdateOrCreateDelivery
                            //string str = await DisplayActionSheet("Update or Create new delivery?", "cancel", null, "Update", "Create");
                            //if (str == "Update")
                            //{
                            //

                            //}
                            //else if (str == "Create")
                            //{
                            //    delivery.CreateTime = DateTime.Now;
                            //    delivery.StartTime = Convert.ToDateTime("0001 - 01 - 01 00:00:00.0000000");
                            //    delivery.EndTime = Convert.ToDateTime("0001 - 01 - 01 00:00:00.0000000");
                            //    delivery.WaitingInMinutes = 0;
                            //    delivery.DeliveryStatusImageSource = "zuti50.png";
                            //    delivery.CourierID = 0;
                            //    delivery.DispatcherID = 0;
                            //    delivery.UserID = Convert.ToInt32(Application.Current.Properties["UserID"]);
                            //    delivery.DeliveryStatus = 0;
                            //    delivery = await deliveryService.CreateDelivery(delivery);
                            //    await DisplayAlert("Success", "New delivery created .", "Ok");

                            //}
                            #endregion
                        }
                        else
                        {
                            done = true;
                            await DisplayAlert("Done", "No changes are made to delivery.", "Ok");
                        }
                    }
                    else
                    {
                        delivery = await deliveryService.CreateDelivery(delivery);

                        done = true;
                        await DisplayAlert("Success", "New delivery created .", "Ok");
                    }
                }
                else
                {
                    //workoround for inserting object of delivery with objects of addresses as propeties
                    var del = delivery;
                    del.StartAddress = null;
                    del.EndAddress   = null;
                    await deliveryService.CreateDelivery(del);
                    await DisplayAlert("Success", "Created new delivery.", "Ok");

                    done = true;
                }
                if (done)
                {
                    await Navigation.PopToRootAsync();
                }
            }
            #endregion
            catch (Exception ex)
            {
                await DisplayAlert("error", "msg: " + ex.Message + "IE : " + ex.InnerException, "ok");
            }
        }
        private async void DeliveryButton_Clicked(object sender, EventArgs e)
        {
            //ActiveCourierModel courier = CourierPicker.SelectedItem as ActiveCourierModel;
            //FullAddressModel startAddress = new FullAddressModel
            //{
            //    UserID = Convert.ToInt32(App.Current.Properties["UserID"].ToString()),
            //    Phone = StartPhone.Text.Trim(),
            //    Name = StartName.Text.Trim(),
            //    Address = StartAddress.Text.Trim(),
            //    LocationID = 1,
            //    Zone = Convert.ToInt32(ZoneStart.Value)

            //};
            //FullAddressModel endAddress = new FullAddressModel
            //{
            //    UserID = Convert.ToInt32(App.Current.Properties["UserID"].ToString()),
            //    Phone = PhoneEnd.Text.Trim(),
            //    Name = NameEnd.Text.Trim(),
            //    Address = EndAddress.Text.Trim(),
            //    LocationID = 1,
            //    Zone = Convert.ToInt32(ZoneEnd.Value)
            //};
            //DeliveryModel newDelivery = new DeliveryModel()
            //{

            //    UserID = Convert.ToInt32(Application.Current.Properties["UserID"].ToString()),
            //    DispatcherID = Convert.ToInt32(Application.Current.Properties["UserID"].ToString()),
            //    CreateTime = DateTime.Now,
            //    DeliveryPrice = Convert.ToDecimal(Price.Text),

            //    PaymentTypeID = PaymentTypePicker.SelectedIndex + 1,
            //    DeliveryTypeID = DeliverTypePicker.SelectedIndex + 1,
            //    CourierID = courier.CourierID,
            //    Description = DeliveryDetails.Text,
            //    DeliveryStatus = 1,
            //    StartAddressID = 2,
            //    EndAddressID = 2


            //};
            if (DeliveryButton.Text.ToLower() == "završi" && PotencialDelivery != null)
            {
                if (await CheckDelivery(PotencialDelivery))
                {
                    try
                    {
                        PotencialDelivery.PaymentTypeID     = PaymentTypePicker.SelectedIndex + 1;
                        PotencialDelivery.DeliveryTypeID    = DeliverTypePicker.SelectedIndex + 1;
                        PotencialDelivery.CourierID         = Convert.ToInt32(Application.Current.Properties["UserID"]);
                        PotencialDelivery.StartAddress.Zone = Convert.ToInt32(ZoneStart.Value);
                        PotencialDelivery.EndAddress.Zone   = Convert.ToInt32(ZoneEnd.Value);
                        PotencialDelivery.CreateTime        = DateTime.Now;

                        ///Nova Start adressa
                        // var postStartAddress = await addressService.PostFullAddress(PotencialDelivery.StartAddress);
                        // PotencialDelivery.StartAddressID = await TypeHelp(postStartAddress);
                        PotencialDelivery = await StartAddressCheck(PotencialDelivery);

                        if (PotencialDelivery == null)
                        {
                            await DisplayAlert("Greska", "", "Potvrdi");
                        }
                        ///Nova End Addressa
                        // var postEndAddress = await addressService.PostFullAddress(startAddress);
                        //PotencialDelivery.EndAddressID = await TypeHelp(postEndAddress);
                        PotencialDelivery = await EndAddressCheck(PotencialDelivery);

                        if (PotencialDelivery == null)
                        {
                            await DisplayAlert("Greska", "", "Potvrdi");
                        }
                        DeliveryModel dtodel = PotencialDelivery;
                        dtodel.StartAddress = null;
                        dtodel.EndAddress   = null;

                        var PostDelivery = await deliveryService.CreateDelivery(dtodel);

                        if (PostDelivery != null)
                        {
                            await DisplayAlert("BaraBara", "Dostava je poslata kuriru", "Potvrdi.");

                            await Navigation.PopAsync();
                        }
                        else
                        {
                            await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo.", "Potvrdi");
                        }
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo. " + Environment.NewLine + "Tekst greške : " + ex.Message, "Potvrdi");
                    }
                }
            }
            else
            {
                if (delivery != null)
                {
                    if (await CheckDelivery(delivery))
                    {
                        switch (delivery.DeliveryStatus)
                        {
                        case 0:
                            delivery.DeliveryStatus = 1;
                            break;

                        case 1:
                            delivery.DeliveryStatus = 1;
                            break;

                        case 2:
                            delivery.DeliveryStatus = 2;
                            break;

                        case 3:
                            delivery.DeliveryStatus = 3;
                            break;

                        case 4:
                            delivery.DeliveryStatus = 4;
                            break;
                        }
                        delivery.PaymentTypeID     = PaymentTypePicker.SelectedIndex + 1;
                        delivery.DeliveryTypeID    = DeliverTypePicker.SelectedIndex + 1;
                        delivery.CourierID         = Convert.ToInt32(Application.Current.Properties["UserID"]);
                        delivery.StartAddress.Zone = Convert.ToInt32(ZoneStart.Value);
                        delivery.EndAddress.Zone   = Convert.ToInt32(ZoneEnd.Value);
                        delivery = await StartAddressCheck(delivery);

                        if (delivery == null)
                        {
                            await DisplayAlert("Greska", "", "Potvrdi");
                        }
                        ///Nova End Addressa
                        // var postEndAddress = await addressService.PostFullAddress(startAddress);
                        //PotencialDelivery.EndAddressID = await TypeHelp(postEndAddress);
                        delivery = await EndAddressCheck(delivery);

                        if (delivery == null)
                        {
                            await DisplayAlert("Greska", "", "Potvrdi");
                        }

                        //if (!checkStartAddress(startAddress))
                        //    {
                        //    // delivery.StartAddressID = delivery.StartAddressID;
                        //    object sAddress = await addressService.PostFullAddress(startAddress);

                        //    delivery.StartAddressID = await TypeHelp(sAddress);

                        //}

                        //    if (!checkEndAddress(endAddress))
                        //    {
                        //       // newDelivery.EndAddressID = delivery.EndAddressID;
                        //    object eAddress = await addressService.PostFullAddress(endAddress);
                        //    delivery.EndAddressID = await TypeHelp(eAddress);
                        //}

                        try
                        {
                            var PostDelivery = await deliveryService.EditDelivery(delivery);

                            if (PostDelivery != null)
                            {
                                await DisplayAlert("BaraBara", "Dostava je ažurirana.", "Potvrdi.");

                                await Navigation.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo.", "Potvrdi");
                            }
                        }
                        catch (Exception ex)
                        {
                            await DisplayAlert("Došlo je do greške.", "Pokušaj ponovo. " + Environment.NewLine + "Tekst greške : " + ex.Message, "Potvrdi");
                        }
                    }
                }
            }
        }