Beispiel #1
0
        public HttpResponseMessage PutLogoutUser(int money, string sessionKey)
        {
            var context = new BankSystemEntities();

            using (context)
            {
                var user = context.Users.FirstOrDefault(u => u.AuthKey == sessionKey);
                if (user == null)
                {
                    throw new InvalidOperationException("There is no such user loged");
                }
                user.AvelableMoney = money;
                context.SaveChanges();

                var model = new UserMoneyModel()
                {
                    Id            = user.Id,
                    AvelableMoney = user.AvelableMoney
                };

                var response =
                    this.Request.CreateResponse(HttpStatusCode.OK, model);

                return(response);
            }
        }
Beispiel #2
0
        public ActionResult Contribute(UserMoneyModel model)
        {
            if (model.Money < model.Contribution)
            {
                this.TempData[GlobalConstants.MessageNameError] = "You can't contribute more than you have!";
                return(this.RedirectToAction("Details", new { id = model.BookId }));
            }

            if (model.Contribution == 0)
            {
                this.TempData[GlobalConstants.MessageNameError] = "You can't contribute 0$!";
                return(this.RedirectToAction("Details", new { id = model.BookId }));
            }

            var user = this.users.GetUser(model.UserId);

            var donation = new Donation()
            {
                DonatorId = user.Id,
                Amount    = model.Contribution,
                BookId    = model.BookId
            };

            this.donations.Add(donation);
            user.Money -= model.Contribution;
            this.users.Update(user);
            this.TempData[GlobalConstants.MessageNameSuccess] = $"Thank you for your donation ({model.Contribution}$)";
            return(this.RedirectToAction("Details", new { id = model.BookId }));
        }
Beispiel #3
0
        public UserMoneyModel GetUser(string sessionKey)
        {
            var context = new BankSystemEntities();

            using (context)
            {
                var user = context.Users.FirstOrDefault(
                    u => u.AuthKey == sessionKey);

                if (user == null)
                {
                    throw new InvalidOperationException("No user with such sessionKey logged");
                }
                else
                {
                    var model = new UserMoneyModel()
                    {
                        Id            = user.Id,
                        AvelableMoney = user.AvelableMoney
                    };

                    return(model);
                }
            }
        }
        private void Pay(object s, EventArgs e)
        {
            var userMoney = new UserMoneyModel
            {
                MoneyId  = MoneyId,
                UserId   = moneyAdminState.User.Id,
                PaidTime = DateTime.Now
            };

            if (!moneyAdminState.IsPaid)
            {
                var dialog = ItemView.Context.CreateDialog(Resource.String.paying_fee, Resource.String.wait);
                dialog.Show();
                ((Activity)ItemView.Context).DoRequest(UserMoneysController.Instance.Add(userMoney), () =>
                {
                    dialog.Dismiss();
                    moneyAdminState.PaidTime = DateTime.Now;
                    moneyAdminState.IsPaid   = true;
                    PayClick?.Invoke(moneyAdminState, e);
                });
            }
            else
            {
                ItemView.Context.ShowConfirmDialog(ItemView.Resources.GetString(Resource.String.confirm_repay),
                                                   $"Do you want to repay for {moneyAdminState.User.Name}?",
                                                   () =>
                {
                    var dialog = ItemView.Context.CreateDialog(Resource.String.repaying_fee, Resource.String.wait);
                    dialog.Show();
                    ((Activity)ItemView.Context).DoRequest(UserMoneysController.Instance
                                                           .Delete(UserMoneysController.Instance.Values
                                                                   .First(x => x.UserId == moneyAdminState.User.Id && x.MoneyId == MoneyId)),
                                                           () =>
                    {
                        dialog.Dismiss();
                        moneyAdminState.IsPaid = false;
                        PayClick?.Invoke(moneyAdminState, e);
                    });
                }, () => { }).Show();
            }
        }