Пример #1
0
        /// <summary>
        /// Ejecuta el intercambio entre ambos personajes.
        /// </summary>
        /// <returns>True si el intercambio culminó con éxito.</returns>
        /// <exception cref="DeadCharactersCannotTradeException">Arrojado cuando al menos uno de los dos personajes se encuentra sin vida.</exception>
        /// <exception cref="NoItemsToShareException">Arrojado cuando la lista de items del personaje a ceder el/los items se encuentra vacía.</exception>
        /// <exception cref="DoesNotContainItemException">Arrojado cuando el personaje a ceder el/los items no contiene al menos uno de los items.</exception>
        public bool RunEncounter()
        {
            Logger.Log($"Un encuentro de intercambio a comenzado.");
            if (!Sharer.IsAlive() || !Receiver.IsAlive())
            {
                throw new DeadCharactersCannotTradeException(
                          "Uno de los dos personajes que iba a participar en el encuentro de intercambio no se encuentra con vida.");
            }
            if (Sharer.Items.Count == 0)
            {
                throw new NoItemsToShareException(
                          "El personaje que iba a ceder un item no contiene ningún item.");
            }


            foreach (var item in Items)
            {
                if (!Sharer.Items.Contains(item))
                {
                    throw new DoesNotContainItemException(
                              "El personaje que iba a compartir items no contiene al menos uno de los items que iba a ceder.");
                }
            }

            foreach (var item in Items)
            {
                Sharer.GiveItem(Receiver, item);
                Logger.Log($"{Receiver.ToString()} ha cedido un {item.ToString()} a {Sharer.ToString()}");
            }

            Logger.Log("El intercambio ha terminado con éxito.");
            return(true);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.Clear;
            vwBackground.AddGestureRecognizer(new UITapGestureRecognizer(() => DismissViewController(true, null)));

            btnFacebook.TouchUpInside += async(sender, e) =>
            {
                DismissViewController(true, null);
                await Sharer.ShareFacebook(Parent, post);

                var apiTask = new ServiceApi().SaveShare(post.Id);
            };

            btnFanword.TouchUpInside += async(sender, e) =>
            {
                DismissViewController(true, null);
                await Sharer.ShareFanword(post);

                FeedTable.GetNewsFeedData(true);
            };

            btnOther.TouchUpInside += async(sender, e) =>
            {
                Debugger.Break();
                DismissViewController(true, null);
                ParentLoadingScreen.Show();
                await Sharer.ShareOther(Parent, post, () =>
                {
                    var apiTask = new ServiceApi().SaveShare(post.Id);
                });

                ParentLoadingScreen.Hide();
            };
        }
Пример #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Sharer sharer = await db.Sharer.FindAsync(id);

            db.Sharer.Remove(sharer);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #4
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,FirstName,LastName")] Sharer sharer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(sharer).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(sharer));
        }
Пример #5
0
        public async Task <ActionResult> Create([Bind(Include = "Id,FirstName,LastName")] Sharer sharer)
        {
            if (ModelState.IsValid)
            {
                db.Sharer.Add(sharer);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(sharer));
        }
Пример #6
0
        // GET: Sharers/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Sharer sharer = await db.Sharer.FindAsync(id);

            if (sharer == null)
            {
                return(HttpNotFound());
            }
            return(View(sharer));
        }
        void SetupViewBindings()
        {
            btnBack.Click += (sender, args) => Finish();

            ShowHelpIfNecessary(TutorialHelper.TagEvents);

            lblTitle.Typeface = CustomTypefaces.RobotoBold;

            var layoutManager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);

            rvDates.SetLayoutManager(layoutManager);

            var times = new List <DateTime>();

            currentTime = DateTime.Now.Date;

            //   cureentTime = DateTime.Now.Date;

            //   currentTime = DateTime.Now.Date.ToUniversalTime();
            var startTime = DateTime.Now.Date.ToUniversalTime().AddDays(-2);

            for (int i = 0; i < 5; i++)
            {
                times.Add(startTime.AddDays(i));
            }

            rvDates.SetAdapter(new CustomRecyclerViewAdapter <DateTime>(times, BindViewHolder, CreateViewHolder, (time, i) => 0));

            adapter = new CustomListAdapter <EventProfile>(new List <EventProfile>(), GetView);
            adapter.NoContentText = "No Events";
            lvEvents.Adapter      = adapter;
            lvEvents.ItemClick   += (sender, e2) =>
            {
                var e = adapter[e2.Position];
                if (Post.Events.Contains((e.Id)))
                {
                    Post.Events.Remove(e.Id);
                }
                else
                {
                    Post.Events.Add(e.Id);
                }

                adapter.NotifyDataSetChanged();
            };
            GetData();

            btnPost.Click += (sender, e) =>
            {
                if (Post.Videos.Any(m => string.IsNullOrEmpty(m.Id)))
                {
                    new AlertDialog.Builder(this)
                    .SetTitle("Video Upload")
                    .SetMessage("You video will be uploaded in the background and the post will be made visible once the upload is complete")
                    .SetPositiveButton("Ok", (o, args) => SavePost())
                    .Show();
                }
                else
                {
                    SavePost();
                }
            };

            if (!string.IsNullOrEmpty(Post.Id))
            {
                btnShare.Visibility = ViewStates.Gone;
            }

            btnShare.Click += (sender, e) =>
            {
                var builder = new AlertDialog.Builder(this);
                builder.SetTitle("Share On");
                ApplicationInfo info = null;
                try
                {
                    info = PackageManager.GetApplicationInfo("com.facebook.katana", 0);
                }
                catch (PackageManager.NameNotFoundException ex)
                {
                }

                if ((Post.Images.Any() || Post.Links.Any() || Post.Videos.Any()) && info != null)
                {
                    builder.SetPositiveButton("Facebook", (s2, e2) =>
                    {
                        Sharer.ShareFacebook(Post);
                        Post.IsShared = true;
                    });
                }

                builder.SetNeutralButton("Other", (s2, e2) =>
                {
                    Sharer.ShareOther(Post);
                    Post.IsShared = true;
                });
                builder.SetNegativeButton("Cancel", (s2, e2) => {});
                builder.Show();
            };
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ShowHelpIfNecessary(TutorialHelper.TagEvents);

            btnBack.TouchUpInside += (sender, e) => NavigationController.PopViewController(true);
            var times = new List <DateTime>();

            currentTime = DateTime.Now.Date.ToUniversalTime();
            var startTime = DateTime.Now.Date.ToUniversalTime().AddDays(-2);

            for (int i = 0; i < 5; i++)
            {
                times.Add(startTime.AddDays(i));
            }

            var layout = cvDates.CollectionViewLayout as UICollectionViewFlowLayout;

            layout.ItemSize = new CoreGraphics.CGSize(UIScreen.MainScreen.Bounds.Width / 5, cvDates.Frame.Height);

            daysSource            = new CustomCollectionSource <DateTime>(times, GetCollectionCell);
            daysSource.ItemClick += (sender, e) =>
            {
                currentTime = e;
                cvDates.ReloadData();
                GetData();
            };
            cvDates.Source = daysSource;

            tvEvents.EstimatedRowHeight = 100;
            tvEvents.RowHeight          = UITableView.AutomaticDimension;
            eventsSource = new CustomListSource <EventProfile>(new List <EventProfile>(), GetCell, (arg1, arg2) => UITableView.AutomaticDimension);
            eventsSource.NoContentText = "No Events";
            eventsSource.ItemClick    += (sender, e) =>
            {
                if (Post.Events.Contains((e.Id)))
                {
                    Post.Events.Remove(e.Id);
                }
                else
                {
                    Post.Events.Add(e.Id);
                }

                tvEvents.ReloadData();
            };
            tvEvents.Source = eventsSource;
            GetData();

            btnPost.TouchUpInside += (sender, e) =>
            {
                if (Post.Videos.Any(m => string.IsNullOrEmpty(m.Id)))
                {
                    var controller = UIAlertController.Create("Video Upload", "You video will be uploaded in the background and the post will be made visible once the upload is complete", UIAlertControllerStyle.Alert);
                    controller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (obj) =>
                    {
                        SavePost();
                    }));
                    PresentViewController(controller, true, null);
                }
                else
                {
                    SavePost();
                }
            };

            if (!string.IsNullOrEmpty(Post.Id))
            {
                btnShare.Hidden = true;
            }

            btnShare.TouchUpInside += (sender, e) =>
            {
                UIActionSheet sheet = new UIActionSheet("Share On");
                if (Post.Images.Any() || Post.Links.Any() || Post.Videos.Any())
                {
                    sheet.AddButton("Facebook");
                }
                sheet.AddButton("Other");
                sheet.AddButton("Cancel");
                sheet.Clicked += async(sender2, e2) =>
                {
                    nint index = e2.ButtonIndex;
                    if (!Post.Images.Any() && !Post.Links.Any() && !Post.Videos.Any())
                    {
                        index++;
                    }
                    if (index == 0)
                    {
                        await Sharer.ShareFacebook(this, Post);

                        Post.IsShared = true;
                    }
                    else if (index == 1)
                    {
                        await Sharer.ShareOther(this, Post, () =>
                        {
                            Post.IsShared = true;
                        });
                    }
                };
                sheet.ShowInView(View);
            };
        }
        void ShareClicked(FeedItem item)
        {
            var view        = activity.LayoutInflater.Inflate(Resource.Layout.ShareOptionsLayout, null);
            var btnFacebook = view.FindViewById <Button>(Resource.Id.btnFacebook);
            var btnFanword  = view.FindViewById <Button>(Resource.Id.btnFanword);
            var btnOther    = view.FindViewById <Button>(Resource.Id.btnOther);

            btnFacebook.Visibility = ViewStates.Gone;

            var builder = new AlertDialog.Builder(activity);

            builder.SetView(view);

            ApplicationInfo info = null;

            try
            {
                info = activity.PackageManager.GetApplicationInfo("com.facebook.katana", 0);
            }
            catch (PackageManager.NameNotFoundException ex)
            {
            }

            activity.ShowProgressDialog();
            var apiTask = new ServiceApi().GetPost(item.Id);

            apiTask.HandleError(activity);
            apiTask.OnSucess(activity, (response) =>
            {
                activity.HideProgressDialog();
                var Post   = response.Result;
                var dialog = builder.Create();
                if ((Post.Images.Any() || Post.Links.Any() || Post.Videos.Any()) && info != null)
                {
                    btnFacebook.Visibility = ViewStates.Visible;
                    btnFacebook.Click     += async(s2, e2) =>
                    {
                        dialog.Dismiss();

                        activity.ShowProgressDialog();
                        await Sharer.ShareFacebook(Post);
                        activity.HideProgressDialog();
                        var saveShareTask = new ServiceApi().SaveShare(Post.Id);
                        saveShareTask.HandleError(activity);
                    };
                }

                btnFanword.Click += async(sender, args) =>
                {
                    dialog.Dismiss();
                    activity.ShowProgressDialog();
                    await Sharer.ShareFanword(Post);
                    GetNewsFeedItems(true);
                    activity.HideProgressDialog();
                };

                btnOther.Click += async(s2, e2) =>
                {
                    dialog.Dismiss();
                    activity.ShowProgressDialog();
                    await Sharer.ShareOther(Post);
                    activity.HideProgressDialog();
                    var saveShareTask = new ServiceApi().SaveShare(Post.Id);
                    saveShareTask.HandleError(activity);
                };

                dialog.Show();
            });
        }