コード例 #1
0
        /// <summary>
        /// A function which attempts to save values to the database
        /// </summary>
        /// <returns>Boolean values</returns>
        private bool SaveCustomerChanges()
        {
            //Initialization of bool
            bool output = false;

            //Assigns the value of the helper class to the class
            bool isNull = ArePropertiesNotNull(CurrentEvent);

            //Assign a context value
            CustomerDatabaseEntities context = new CustomerDatabaseEntities();

            //If the check for not null is not true
            if (!isNull)
            {
                //Using the helper function which converts the image to bytes
                byte[] imageBytes  = ConvertImageToByteArray(ImagePathOfEventImage);
                byte[] imageBytes2 = ConvertImageToByteArray(ImagePathOfEventLayout);

                #region Saving to the database

                CurrentEvent.eventPicture     = imageBytes;
                CurrentEvent.eventLayout      = imageBytes2;
                CurrentEvent.eventGenre       = EventGenre.Trim();
                CurrentEvent.eventTitle       = EventTitle.Trim();
                CurrentEvent.showOnHomePage   = ShowOnHomePage.Value;
                CurrentEvent.eventDescription = EventDescription.Trim();
                CurrentEvent.eventStart       = EventStart;
                CurrentEvent.eventEnd         = EventEnd;
                CurrentEvent.capacity         = Capacity;
                CurrentEvent.eventLocation    = EventLocation.Trim();
                CurrentEvent.eventAddress     = EventAddress.Trim();
                context.Event_Details.Add(CurrentEvent);

                //Save changes to the database
                context.SaveChanges();
                context.Dispose();

                #endregion

                //Return true if this function succeeds
                output = true;
                return(output);
            }

            //Otherwise return false
            return(output);
        }
コード例 #2
0
        private async void AddEvent()
        {
            if (IsReadOnly)
            {
                return;
            }

            if (string.IsNullOrEmpty(EventTitle) || string.IsNullOrEmpty(EventTitle.Trim()))
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Event title must not be empty"));
                return;
            }

            if (EndDate.CompareTo(DateTime.UtcNow.ToLocalTime()) != 1 || StartDate.CompareTo(DateTime.UtcNow.ToLocalTime()) != 1)
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "End Date or Start Date must be later than now"));
                return;
            }

            if (EndDate.CompareTo(StartDate) == 0)
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Start time & end time must be different when the dates are equal"));
                return;
            }

            if (EndDate.CompareTo(StartDate) > 0)
            {
                if (BaseView != null && BaseView.CheckInternetConnection())
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true));

                    if (IsEditMode)
                    {
                        if (mOldRepeat.Equals("once"))
                        {
                            var result =
                                await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                      new Periodicity()
                            {
                            }, "all", true, StartTimestampOfSelectedOccurrence);

                            if (result != null)
                            {
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}",result.Result, result.ErrorCode )));
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode)));
                                if (result.Response.Status.Equals("success"))
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }
                            Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
                            mCacheService.NeedReloadEvent = true;
                            Close(this);
                            return;
                        }
                        //edit unavaiability
                        Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, SharedTextSource.GetText("EditEventText"), SharedTextSource.GetText("AreYouSureEventText"), SharedTextSource.GetText("CancelText"), null, new string[] { SharedTextSource.GetText("EditFutureEventsText"), SharedTextSource.GetText("EditEventOnlyText") },
                                                                               async() =>
                        {
                            var result =
                                await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                      new Periodicity()
                            {
                                Repeat            = SelectedRepeat,
                                OccurrencesAmount = Times,
                                Exceptions        = new List <PeriodicityException>()
                                {
                                }
                            }, "all", false, StartTimestampOfSelectedOccurrence);

                            if (result != null)
                            {
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}", result.Result, result.ErrorCode)));
                                if (result.Response.Status.Equals("success"))
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }

                            mCacheService.NeedReloadEvent = true;
                            Close(this);
                        }, async() =>
                        {
                            var result =
                                await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                      new Periodicity()
                            {
                            }, "all", true, StartTimestampOfSelectedOccurrence);

                            if (result != null)
                            {
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}",result.Result, result.ErrorCode )));
                                //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode)));
                                if (result.Response.Status.Equals("success"))
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }

                            mCacheService.NeedReloadEvent = true;
                            Close(this);
                        }));
                    }
                    else
                    {
                        //add unavaiability
                        var result =
                            await mApiService.CreateUnavailabilities(mCacheService.CurrentUser.UserId, mCacheService.ParkingId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate),
                                                                     new Periodicity()
                        {
                            Repeat            = SelectedRepeat,
                            OccurrencesAmount = Times
                        }, "all");

                        if (result != null)
                        {
                            //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result));
                            //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Equals("success") ? "Success" : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode)));
                            if (result.Response.Status.Equals("success"))
                            {
                                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                            }
                            else
                            {
                                if (result.ApiError.Status.Equals("999"))
                                {
                                    Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}", result.Response.ErrorCode), "Ok", null));
                                }
                                else
                                {
                                    Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                                }
                            }
                        }

                        mCacheService.NeedReloadEvent = true;
                        Close(this);
                    }



                    Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
                }
                else
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
                }
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "End Date must be later than Start Date"));
            }
        }