Exemplo n.º 1
0
        public async Task <IActionResult> Return(string payerId)
        {
            var user = await _userManager.GetUserAsync(User);

            user.PinchPayerId = payerId;
            _context.SaveChanges();

            return(RedirectToAction("Method"));
        }
Exemplo n.º 2
0
        public IActionResult Save(AddPledgeVm model)
        {
            if (!ModelState.IsValid)
            {
                return RedirectToAction("Details", "BulkBuy", new { id = model.Id });
            }

            var bulkBuy = _context.BulkBuys
                .FirstOrDefault(x => x.DisplayId == model.Id
                                     && !x.IsDeleted);

            if (bulkBuy == null)
            {
                ModelState.AddModelError("", $"Could not find a Bulk Buy with ID: {model.Id}");
                return RedirectToAction("Details", "BulkBuy", new { id = model.Id });
            }

            var userId = _userManager.GetUserId(User);
            var existing = _context.Pledges
                .FirstOrDefault(x => x.UserId == userId
                                     && x.BulkBuy.DisplayId == model.Id
                                     && !x.IsDeleted);

            if (existing != null)
            {
                existing.OrderDetails = model.OrderDetails;
                existing.PledgeAmount = model.PledgeAmount;
                _context.SaveChanges();
            }
            else
            {
                var pledge = new Pledge()
                {
                    UserId = userId,
                    BulkBuyId = bulkBuy.Id,
                    CreatedDate = DateTime.UtcNow,
                    OrderDetails = model.OrderDetails,
                    PledgeAmount = model.PledgeAmount
                };
                _context.Pledges.Add(pledge);
                _context.SaveChanges();
            }

            return RedirectToAction("Details", "BulkBuy", new { id = bulkBuy.DisplayId });
        }
Exemplo n.º 3
0
        public IActionResult New(CreateVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var bulkBuy = new BulkBuy()
            {
                DisplayId   = _shortCodeService.GenerateId(IdPrefix.BULK_BUY),
                Name        = model.Name,
                Description = model.Description,
                DueDate     = model.ClosingDate,
                OwnerId     = _userManager.GetUserId(User),
                CreatedDate = DateTime.UtcNow
            };

            _context.BulkBuys.Add(bulkBuy);
            _context.SaveChanges();

            return(RedirectToAction("Details", new { id = bulkBuy.DisplayId }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Account(AccountVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            user.StreetAddress = model.StreetAddress;
            user.Postcode      = model.Postcode;
            user.Suburb        = model.Suburb;
            user.PhoneNumber   = model.MobileNumber;

            _context.SaveChanges();

            var merchant = await _organiserService.GetMerchant(user.Id, _appSettings.Pinch.IsLive);

            if (merchant != null)
            {
                var response = await _organiserService.UpdateMerchant(user.Id, _appSettings.Pinch.IsLive,
                                                                      _appSettings.Pinch.MerchantId, _appSettings.Pinch.SecretKey);

                if (!response.Successful)
                {
                    ModelState.AddModelError("", string.Join(" - ", response.ErrorMessages.Select(x => x.ErrorMessage)));
                    return(View(model));
                }
            }
            else
            {
                var response = await _organiserService.CreateMerchant(user.Id, _appSettings.Pinch.IsLive,
                                                                      _appSettings.Pinch.MerchantId, _appSettings.Pinch.SecretKey);

                if (!response.Successful)
                {
                    ModelState.AddModelError("", string.Join(" - ", response.ErrorMessages.Select(x => x.ErrorMessage)));
                    return(View(model));
                }
            }

            return(RedirectToAction("Account"));
        }