public async Task <ActionResult> ConfirmOrder(int?id)
        {
            if (id != null)
            {
                bool result = orderService.ConfirmOrder(id.Value, User.Identity.GetUserId <int>());
                var  order  = orderService.GetOrder(id.Value, i => i.CurrentStatus, i => i.Seller.User, i => i.Buyer.User);
                if (result && order != null)
                {
                    if (order.JobId != null)
                    {
                        BackgroundJob.Delete(order.JobId);
                        order.JobId = null;
                    }

                    await orderService.SaveOrderAsync();

                    order.JobId = MarketplaceMVCHangfire.SetLeaveFeedbackJob(order.SellerId, order.BuyerId.Value, order.Id, TimeSpan.FromDays(15));


                    MarketplaceMVCHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.User.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme));

                    MarketplaceMVCHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.User.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme));

                    await orderService.SaveOrderAsync();


                    TempData["orderBuyStatus"] = "Спасибо за подтверждение сделки! Сделка успешно закрыта.";
                    return(RedirectToAction("BuyDetails", "Order", new { id }));
                }
            }
            return(HttpNotFound());
        }
Ejemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            ConfigureAutofac(app);
            app.MapSignalR();
            AutoMapperConfiguration.Configure();
            MarketplaceMVCHangfire.ConfigureHangfire(app);

            GlobalConfiguration.Configuration
            .UseSqlServerStorage("DefaultConnection");

            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("ru");



            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new MyAuthorizationFilter() }
            });

            app.UseHangfireServer();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create(CreateOfferViewModel model)
        {
            int         currentUserId = User.Identity.GetUserId <int>();
            Game        game          = gameService.GetGameByValue(model.Game);
            UserProfile user          = await userProfileService.GetUserProfileByIdAsync(currentUserId);

            if (ModelState.IsValid && game != null && user != null)
            {
                var offer = Mapper.Map <CreateOfferViewModel, Offer>(model);
                offer.UserProfile = user;
                offer.Game        = game;
                offerService.CreateOffer(offer);
                offerService.SaveOffer();
                if (Request.Url != null)
                {
                    offer.JobId = MarketplaceMVCHangfire.SetDeactivateOfferJob(offer.Id,
                                                                               Url.Action("Activate", "Offer", new { id = offer.Id }, Request.Url.Scheme), TimeSpan.FromDays(30));
                }
                offerService.SaveOffer();
            }

            return(View(model));
        }
        public async Task <ActionResult> Buy(CheckoutViewModel model)
        {
            Offer offer = await offerService.GetOfferAsync(model.OfferId, o => o.UserProfile, o => o.UserProfile.User, o => o.Order, o => o.Order.StatusLogs, o => o.Order.CurrentStatus);

            if (offer != null && offer.Order == null && offer.State == OfferState.active && offer.UserProfileId != User.Identity.GetUserId <int>())
            {
                var currentUserId = User.Identity.GetUserId <int>();
                var user          = userProfileService.GetUserProfile(u => u.Id == currentUserId, i => i.User);
                var mainCup       = userProfileService.GetUserProfileByName("playerup");
                if (user != null && mainCup != null && user.Balance >= model.OrderSum)
                {
                    //var amount = Decimal.Parse(Request.Form["ik_am"]);

                    offer.Order = new Order
                    {
                        BuyerId     = currentUserId,
                        SellerId    = offer.UserProfileId,
                        CreatedDate = DateTime.Now
                    };
                    offer.State = OfferState.closed;


                    if (mainCup != null)
                    {
                        var seller = offer.UserProfile;
                        var buyer  = user;

                        if (offer.SellerPaysMiddleman)
                        {
                            offer.Order.Sum = offer.Price;
                            offer.Order.AmmountSellerGet = offer.Price - offer.MiddlemanPrice.Value;
                            if (buyer.Balance >= offer.Order.Sum)
                            {
                                transactionService.CreateTransaction(new Transaction
                                {
                                    Amount      = offer.Order.Sum,
                                    Order       = offer.Order,
                                    Receiver    = mainCup,
                                    Sender      = buyer,
                                    CreatedDate = DateTime.Now
                                });
                                buyer.Balance   -= offer.Order.Sum;
                                mainCup.Balance += offer.Order.Sum;
                            }
                            else
                            {
                                return(View("NotEnoughMoney"));
                            }
                        }
                        else
                        {
                            offer.Order.Sum = offer.Price + offer.MiddlemanPrice.Value;
                            offer.Order.AmmountSellerGet = offer.Price;
                            if (buyer.Balance >= offer.Order.Sum)
                            {
                                transactionService.CreateTransaction(new Transaction
                                {
                                    Amount      = offer.Order.Sum,
                                    Order       = offer.Order,
                                    Receiver    = mainCup,
                                    Sender      = buyer,
                                    CreatedDate = DateTime.Now
                                });
                                buyer.Balance   -= offer.Order.Sum;
                                mainCup.Balance += offer.Order.Sum;
                            }
                            else
                            {
                                return(View("NotEnoughMoney"));
                            }
                        }
                        offer.Order.StatusLogs.AddLast(new StatusLog()
                        {
                            OldStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.OrderCreating),
                            NewStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.BuyerPaying),
                            TimeStamp = DateTime.Now
                        });

                        offer.Order.StatusLogs.AddLast(new StatusLog()
                        {
                            OldStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.BuyerPaying),
                            NewStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.MiddlemanFinding),
                            TimeStamp = DateTime.Now
                        });
                        offer.Order.CurrentStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.MiddlemanFinding);

                        offer.Order.BuyerChecked  = false;
                        offer.Order.SellerChecked = false;

                        if (offer.Order.JobId != null)
                        {
                            BackgroundJob.Delete(offer.Order.JobId);
                            offer.Order.JobId = null;
                        }

                        if (offer.JobId != null)
                        {
                            BackgroundJob.Delete(offer.JobId);
                            offer.JobId = null;
                        }

                        orderService.SaveOrder();

                        MarketplaceMVCHangfire.SetSendEmailChangeStatus(offer.Order.Id, seller.User.Email, offer.Order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = offer.Order.Id }, protocol: Request.Url.Scheme));

                        MarketplaceMVCHangfire.SetSendEmailChangeStatus(offer.Order.Id, buyer.User.Email, offer.Order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = offer.Order.Id }, protocol: Request.Url.Scheme));
                        offer.Order.JobId = MarketplaceMVCHangfire.SetOrderCloseJob(offer.Order.Id, TimeSpan.FromDays(1));
                        //_orderService.UpdateOrder(order);
                        orderService.SaveOrder();
                        TempData["orderBuyStatus"] = "Оплата прошла успешно";

                        return(RedirectToAction("BuyDetails", "Order", new { id = offer.Order.Id }));
                    }
                }
            }
            return(HttpNotFound());
        }
        public async Task <ActionResult> ProvideData(AccountInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var accountInfo = Mapper.Map <AccountInfoViewModel, AccountInfo>(model);

                var moderator = await userProfileService.GetUserProfileAsync(u => u.Id == model.ModeratorId, i => i.User);

                bool moderIsInrole = true;
                if (moderator != null)
                {
                    foreach (var role in moderator.User.Roles)
                    {
                        if (role.RoleId == 2 && role.UserId == moderator.Id)
                        {
                            moderIsInrole = true;
                        }
                    }
                }
                if (moderIsInrole)
                {
                    var order = orderService.GetOrder(model.AccountLogin, model.ModeratorId, model.SellerId,
                                                      model.BuyerId, i => i.CurrentStatus, i => i.StatusLogs, i => i.Seller.User, i => i.Buyer.User);
                    if (order != null)
                    {
                        if (order.CurrentStatus != null)
                        {
                            if (order.CurrentStatus.Value == OrderStatuses.SellerProviding)
                            {
                                order.StatusLogs.AddLast(new StatusLog()
                                {
                                    OldStatus = order.CurrentStatus,
                                    NewStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.MiddlemanChecking),
                                    TimeStamp = DateTime.Now
                                });
                                order.CurrentStatus = orderStatusService.GetOrderStatusByValue(OrderStatuses.MiddlemanChecking);


                                order.BuyerChecked  = false;
                                order.SellerChecked = false;
                                accountInfo.Order   = order;
                                accountInfoService.CreateAccountInfo(accountInfo);
                                if (order.JobId != null)
                                {
                                    BackgroundJob.Delete(order.JobId);
                                    order.JobId = null;
                                }
                                //order.JobId = MarketHangfire.SetOrderCloseJob(order.Id, TimeSpan.FromMinutes(5));
                                await orderService.SaveOrderAsync();


                                MarketplaceMVCHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.User.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme));

                                MarketplaceMVCHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.User.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme));
                                TempData["orderSellStatus"] = "Ваши данные были отправлены на проверку гаранту";
                                return(RedirectToAction("SellDetails", "Order", new { id = order.Id }));
                            }
                        }
                    }
                }
            }
            return(HttpNotFound());
        }