public ActionResult ConfirmOrder(int?id) { if (id != null) { bool result = _orderService.ConfirmOrder(id.Value, User.Identity.GetUserId()); var order = _orderService.GetOrder(id.Value, i => i.CurrentStatus, i => i.Seller.ApplicationUser, i => i.Buyer.ApplicationUser); if (result && order != null) { if (order.JobId != null) { BackgroundJob.Delete(order.JobId); order.JobId = null; } _orderService.SaveOrder(); order.JobId = MarketHangfire.SetLeaveFeedbackJob(order.SellerId, order.BuyerId, order.Id, TimeSpan.FromDays(15)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); _orderService.SaveOrder(); TempData["orderBuyStatus"] = "Спасибо за подтверждение сделки! Сделка успешно закрыта."; return(RedirectToAction("BuyDetails", "Order", new { id })); } } return(HttpNotFound()); }
public ActionResult ConfirmAbortOrder(int?id) { if (id != null) { bool result = _orderService.ConfirmAbortOrder(id.Value, User.Identity.GetUserId()); var order = _orderService.GetOrder(id.Value, i => i.Seller.ApplicationUser, i => i.Buyer.ApplicationUser, i => i.CurrentStatus); if (result && order != null) { if (order.JobId != null) { BackgroundJob.Delete(order.JobId); order.JobId = null; } _orderService.SaveOrder(); if (Request.Url != null) { MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); } _orderService.SaveOrder(); return(RedirectToAction("BuyDetails", "Order", new { id })); } } return(HttpNotFound()); }
public ActionResult ProvideDataToBuyer(AccountInfoViewModel model) { if (ModelState.IsValid) { var accountInfo = Mapper.Map <AccountInfoViewModel, AccountInfo>(model); var buyerOrder = _orderService.GetOrder(model.SteamLogin, model.ModeratorId, model.SellerId, model.BuyerId, i => i.CurrentStatus, i => i.StatusLogs, i => i.AccountInfos, i => i.Seller.ApplicationUser, i => i.Buyer.ApplicationUser); if (buyerOrder?.CurrentStatus != null) { if (buyerOrder.CurrentStatus.Value == OrderStatuses.MidddlemanChecking) { buyerOrder.StatusLogs.AddLast(new StatusLog() { OldStatus = buyerOrder.CurrentStatus, NewStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.BuyerConfirming), TimeStamp = DateTime.Now }); buyerOrder.CurrentStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.BuyerConfirming); buyerOrder.BuyerChecked = false; buyerOrder.SellerChecked = false; buyerOrder.AccountInfos.Add(accountInfo); _accountInfoService.CreateAccountInfo(accountInfo); if (buyerOrder.JobId != null) { BackgroundJob.Delete(buyerOrder.JobId); buyerOrder.JobId = null; } _orderService.SaveOrder(); buyerOrder.JobId = MarketHangfire.SetConfirmOrderJob(buyerOrder.Id, TimeSpan.FromDays(2)); if (Request.Url != null) { MarketHangfire.SetSendEmailChangeStatus(buyerOrder.Id, buyerOrder.Seller.ApplicationUser.Email, buyerOrder.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = buyerOrder.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailAccountData(accountInfo.Login, accountInfo.Password, accountInfo.Email, accountInfo.EmailPassword, accountInfo.AdditionalInformation, buyerOrder.Buyer.ApplicationUser.Email); } _orderService.SaveOrder(); return(RedirectToAction("ProvideDataToBuyer", new { orderId = buyerOrder.Id })); } } } return(HttpNotFound()); }
public ActionResult ProcessOrder(int?id) { if (id != null) { var order = _orderService.GetOrder(id.Value, i => i.CurrentStatus, i => i.Seller.ApplicationUser, i => i.Buyer.ApplicationUser, i => i.StatusLogs); if (order.CurrentStatus != null) { if (order.CurrentStatus.Value == OrderStatuses.MiddlemanFinding) { order.StatusLogs.AddLast(new StatusLog() { OldStatus = order.CurrentStatus, NewStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.SellerProviding), TimeStamp = DateTime.Now }); order.CurrentStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.SellerProviding); order.BuyerChecked = false; order.SellerChecked = false; order.MiddlemanId = User.Identity.GetUserId(); if (order.JobId != null) { BackgroundJob.Delete(order.JobId); order.JobId = null; } _orderService.SaveOrder(); order.JobId = MarketHangfire.SetOrderCloseJob(order.Id, TimeSpan.FromDays(1)); if (Request.Url != null) { MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); } _orderService.SaveOrder(); return(RedirectToAction("MyOrderList")); } } } return(HttpNotFound()); }
public ActionResult ProvideData(AccountInfoViewModel model) { if (ModelState.IsValid) { var accountInfo = Mapper.Map <AccountInfoViewModel, AccountInfo>(model); var moderator = _userProfileService.GetUserProfile(u => u.Id == model.ModeratorId, i => i.ApplicationUser); bool moderIsInrole = false; if (moderator != null) { foreach (var role in moderator.ApplicationUser.Roles) { if (role.RoleId == "2" && role.UserId == moderator.Id) { moderIsInrole = true; } } } if (moderIsInrole) { var order = _orderService.GetOrder(model.SteamLogin, model.ModeratorId, model.SellerId, model.BuyerId, i => i.CurrentStatus, i => i.StatusLogs, i => i.Seller.ApplicationUser, i => i.Buyer.ApplicationUser); 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.MidddlemanChecking), TimeStamp = DateTime.Now }); order.CurrentStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.MidddlemanChecking); 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)); _orderService.SaveOrder(); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.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()); }
public void MoneyIn() { var secretKey = "fVdVZaZjAkkd8h3A"; var pars = new SortedDictionary <string, string>(); var keys = Request.Form.AllKeys; foreach (var key in keys.Where(key => key.IndexOf("ik_") >= 0 && key != "ik_sign")) { pars.Add(key, Request.Form[key]); } var hash = string.Join(":", pars.Select(x => x.Value).ToArray().Concat(new[] { secretKey })); var md5 = new MD5CryptoServiceProvider(); var isSame = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(hash))) == Request.Form["ik_sign"]; bool isOrderPay = false; if (isSame) { var userId = Request.Form["ik_x_user_id"]; var offerId = Request.Form["ik_x_offer_id"]; var mainCup = _userProfileService.GetUserProfileByName("palyerup"); if (offerId != null && userId != null && mainCup != null) { var user = _userProfileService.GetUserProfile(u => u.Id == userId, i => i.ApplicationUser); Offer offer = _offerService.GetOffer(int.Parse(offerId), o => o.UserProfile, o => o.UserProfile.ApplicationUser, o => o.Order, o => o.Order.StatusLogs, o => o.Order.CurrentStatus); decimal buyerPay = 0; if (offer.SellerPaysMiddleman) { buyerPay = offer.Price; } else { buyerPay = offer.Price + offer.MiddlemanPrice.Value; } if (buyerPay == Decimal.Parse(Request.Form["ik_am"])) { if (offer != null && offer.UserProfile.Id != User.Identity.GetUserId()) { offer.Order = new Order { Buyer = user, Seller = offer.UserProfile, DateCreated = DateTime.Now }; Order order = offer.Order; offer.State = OfferState.closed; order.StatusLogs.AddLast(new StatusLog() { OldStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.OrderCreating), NewStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.BuyerPaying), TimeStamp = DateTime.Now }); order.StatusLogs.AddLast(new StatusLog() { OldStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.BuyerPaying), NewStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.MiddlemanFinding), TimeStamp = DateTime.Now }); order.CurrentStatus = _orderStatusService.GetOrderStatusByValue(OrderStatuses.MiddlemanFinding); _transactionService.CreateTransaction(new Transaction { Amount = buyerPay, Order = order, Receiver = mainCup, Sender = user, TransactionDate = DateTime.Now }); if (offer.JobId != null) { BackgroundJob.Delete(offer.JobId); offer.JobId = null; } _offerService.SaveOffer(); isOrderPay = true; MarketHangfire.SetSendEmailChangeStatus(order.Id, offer.UserProfile.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, user.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); offer.Order.JobId = MarketHangfire.SetOrderCloseJob(order.Id, TimeSpan.FromDays(1)); _orderService.SaveOrder(); } } } // если пополняем баланс if (userId != null && !isOrderPay) { var user = _userProfileService.GetUserProfile(u => u.Id == userId); var amount = Decimal.Parse(Request.Form["ik_am"]); user.Balance += amount; _billingService.CreateBilling(new Billing { User = user, DateCeated = DateTime.Now, Amount = amount }); _userProfileService.SaveUserProfile(); } else if (!isOrderPay) { string currentUserId = User.Identity.GetUserId(); var currentUser = _userProfileService.GetUserProfileById(currentUserId); if (currentUser != null) { var amount = Decimal.Parse(Request.Form["ik_am"]); currentUser.Balance += amount; _billingService.CreateBilling(new Billing { User = currentUser, DateCeated = DateTime.Now, Amount = amount }); _userProfileService.SaveUserProfile(); } } } }
public async Task <ActionResult> Checkoutme(CheckoutViewModel model) { //UserProfile buyer = _db.UserProfiles.Get(User.Identity.GetUserId()); Offer offer = _offerService.GetOffer(model.OfferId, o => o.UserProfile, o => o.UserProfile.ApplicationUser, 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()) { var currentUserId = User.Identity.GetUserId(); var user = _userProfileService.GetUserProfile(u => u.Id == currentUserId, i => i.ApplicationUser); var mainCup = _userProfileService.GetUserProfileByName("palyerup"); 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, DateCreated = 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, TransactionDate = 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, TransactionDate = 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(); MarketHangfire.SetSendEmailChangeStatus(offer.Order.Id, seller.ApplicationUser.Email, offer.Order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = offer.Order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(offer.Order.Id, buyer.ApplicationUser.Email, offer.Order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = offer.Order.Id }, protocol: Request.Url.Scheme)); offer.Order.JobId = MarketHangfire.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 ActionResult Close(int?Id) { string userId = User.Identity.GetUserId(); if (userId != null && Id != null) { var order = _orderService.GetOrder(Id.Value, i => i.Seller, i => i.Seller.ApplicationUser, i => i.Buyer.ApplicationUser, i => i.CurrentStatus, i => i.Buyer, i => i.Middleman, i => i.Seller); bool closeResult = false; if (order != null) { if (userId == order.BuyerId) { closeResult = _orderService.CloseOrderByBuyer(order.Id); if (closeResult) { if (order.JobId != null) { BackgroundJob.Delete(order.JobId); order.JobId = null; } TempData["orderBuyStatus"] = "Сделка закрыта."; _orderService.SaveOrder(); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); return(RedirectToAction("BuyDetails", new { id = order.Id })); } } else if (userId == order.SellerId) { closeResult = _orderService.CloseOrderBySeller(order.Id); if (closeResult) { if (order.JobId != null) { BackgroundJob.Delete(order.JobId); order.JobId = null; } TempData["orderSellStatus"] = "Сделка закрыта."; _orderService.SaveOrder(); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); return(RedirectToAction("SellDetails", new { id = order.Id })); } } else if (userId == order.MiddlemanId) { closeResult = _orderService.CloseOrderByMiddleman(order.Id); if (closeResult) { if (order.JobId != null) { BackgroundJob.Delete(order.JobId); order.JobId = null; } _orderService.SaveOrder(); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Seller.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("SellDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); MarketHangfire.SetSendEmailChangeStatus(order.Id, order.Buyer.ApplicationUser.Email, order.CurrentStatus.DuringName, Url.Action("BuyDetails", "Order", new { id = order.Id }, protocol: Request.Url.Scheme)); } } if (order.BuyerId == userId) { return(RedirectToAction("BuyDetails", "Order", new { id = order.Id })); } else if (order.SellerId == userId) { return(RedirectToAction("SellDetails", "Order", new { id = order.Id })); } } } return(HttpNotFound()); }