Beispiel #1
0
        public virtual async Task EditItinerary(AmblOnGraph amblGraph, string username, string entLookup, Itinerary itinerary, List <ActivityLocationLookup> activityLocations)
        {
            State.Loading = true;

            ensureStateObject();

            var activitiesList = new List <Activity>();

            if (!activityLocations.IsNullOrEmpty())
            {
                activitiesList = await addLocationFromActivity(amblGraph, username, entLookup, activityLocations);
            }

            var existing = State.UserItineraries.FirstOrDefault(x => x.ID == itinerary.ID);

            if (existing != null)
            {
                if (existing.Editable)
                {
                    var success = true;

                    var itineraryResp = await amblGraph.EditItinerary(username, entLookup, itinerary);

                    if (!itineraryResp.Status)
                    {
                        success = false;
                    }

                    if (success)
                    {
                        await itinerary.ActivityGroups.Each(async (activityGroup) =>
                        {
                            var agExisting = existing.ActivityGroups.FirstOrDefault(x => x.ID == activityGroup.ID);

                            if (agExisting == null)
                            {
                                var addActGResp = await amblGraph.AddActivityGroup(username, entLookup, itinerary.ID, activityGroup);

                                if (addActGResp.Status)
                                {
                                    activityGroup.ID = addActGResp.Model;

                                    await activityGroup.Activities.Each(async(activity) =>
                                    {
                                        var addActResp = new BaseResponse <Guid>();

                                        if (activity.ID == Guid.Empty)
                                        {
                                            addActResp = await amblGraph.AddActivityToAG(username, entLookup, itinerary.ID, activityGroup.ID, activity);

                                            activity.ID = addActResp.Model;

                                            var exists = activitiesList?.FirstOrDefault(x => x.Title == activity.Title);

                                            if (exists != null)
                                            {
                                                exists.ID = activity.ID;

                                                addActResp = await amblGraph.AddActivityToAG(username, entLookup, itinerary.ID, activityGroup.ID, exists);
                                            }
                                        }

                                        else
                                        {
                                            var exists = activitiesList?.FirstOrDefault(x => x.ID == activity.ID);

                                            addActResp = await amblGraph.AddActivityToAG(username, entLookup, itinerary.ID, activityGroup.ID, exists);
                                        }

                                        activity.ID = addActResp.Model;

                                        if (!addActResp.Status)
                                        {
                                            success = false;
                                        }
                                    });
                                }
                                else
                                {
                                    success = false;
                                }
                            }
                            else
                            {
                                await activityGroup.Activities.Each(async(activity) =>
                                {
                                    var aExisting = agExisting.Activities.FirstOrDefault(x => x.ID == activity.ID);

                                    if (aExisting == null)
                                    {
                                        var exists = activitiesList?.FirstOrDefault(x => x.ID == activity.ID);

                                        var addActResp = await amblGraph.AddActivityToAG(username, entLookup, itinerary.ID, activityGroup.ID, exists ?? activity);

                                        activitiesList.Remove(exists);

                                        activity.ID = addActResp.Model;

                                        if (!addActResp.Status)
                                        {
                                            success = false;
                                        }
                                    }
                                    else
                                    {
                                        var exists = activitiesList?.FirstOrDefault(x => x.ID == activity.ID);

                                        var editActResp = await amblGraph.EditActivity(username, entLookup, exists ?? activity);

                                        if (!editActResp.Status)
                                        {
                                            success = false;
                                        }
                                    }
                                });

                                var editActGResp = await amblGraph.EditActivityGroup(username, entLookup, activityGroup);

                                if (!editActGResp.Status)
                                {
                                    success = false;
                                }
                            }
                        });

                        await existing.ActivityGroups.Each(async (activityGroup) =>
                        {
                            var agNew = itinerary.ActivityGroups.FirstOrDefault(x => x.ID == activityGroup.ID);

                            if (agNew == null)
                            {
                                await activityGroup.Activities.Each(async(activity) =>
                                {
                                    var delActResp = await amblGraph.DeleteActivity(username, entLookup, itinerary.ID, activityGroup.ID, activity.ID);

                                    if (!delActResp.Status)
                                    {
                                        success = false;
                                    }
                                });

                                if (success)
                                {
                                    var delActGResp = await amblGraph.DeleteActivityGroup(username, entLookup, itinerary.ID, activityGroup.ID);

                                    if (!delActGResp.Status)
                                    {
                                        success = false;
                                    }
                                }
                            }
                            else
                            {
                                await activityGroup.Activities.Each(async(activity) =>
                                {
                                    var aNew = agNew.Activities.FirstOrDefault(x => x.ID == activity.ID);

                                    if (aNew == null)
                                    {
                                        var delActResp = await amblGraph.DeleteActivity(username, entLookup, itinerary.ID, activityGroup.ID, activity.ID);

                                        if (!delActResp.Status)
                                        {
                                            success = false;
                                        }
                                    }
                                });
                            }
                        });
                    }

                    if (success)
                    {
                        State.UserItineraries = await fetchUserItineraries(amblGraph, username, entLookup);
                    }
                    else
                    {
                        State.Error = "General Error updating user itinerary.";
                    }
                }
                else
                {
                    State.Error = "Cannot edit a shared itinerary.";
                }
            }
            else
            {
                State.Error = "Itinerary not found.";
            }

            State.Loading = false;
        }
Beispiel #2
0
        public virtual async Task DeleteItineraries(AmblOnGraph amblGraph, string username, string entLookup, List <Guid> itineraryIDs)
        {
            ensureStateObject();

            var success = true;

            await itineraryIDs.Each(async (itineraryID) =>
            {
                var itinerary = State.UserItineraries.FirstOrDefault(x => x.ID == itineraryID);

                if (itinerary != null)
                {
                    await itinerary.ActivityGroups.Each(async(activityGroup) =>
                    {
                        await activityGroup.Activities.Each(async(activity) =>
                        {
                            var actResp = await amblGraph.DeleteActivity(username, entLookup, itinerary.ID, activityGroup.ID, activity.ID);

                            if (!actResp.Status)
                            {
                                success = false;
                            }
                        });

                        if (success)
                        {
                            var actGroupResp = await amblGraph.DeleteActivityGroup(username, entLookup, itinerary.ID, activityGroup.ID);

                            if (!actGroupResp.Status)
                            {
                                success = false;
                            }
                        }
                    });

                    if (success)
                    {
                        var itineraryResp = await amblGraph.DeleteItinerary(username, entLookup, itineraryID);

                        if (!itineraryResp.Status)
                        {
                            success = false;
                        }
                    }

                    if (success)
                    {
                        var existing = State.UserItineraries.FirstOrDefault(x => x.ID == itineraryID);

                        if (existing != null)
                        {
                            State.UserItineraries.Remove(existing);
                        }

                        State.UserItineraries = State.UserItineraries.Distinct().ToList();
                    }
                }
                else
                {
                    success = false;
                }
            });

            if (!success)
            {
                State.Error = "General Error";
            }

            State.Loading = false;
        }