Ejemplo n.º 1
0
        public virtual ActionResult CreateFeedbackForm(FeedbackForm form, int? threadId = null, bool skipAnswerFeedback = false)
        {
            Thread thread;

            if(threadId == null)
                thread = Repository.Thread.Get(form.ThreadId);
            else
                thread = Repository.Thread.Get((int)threadId);

            if (!IsAuthor(thread))
            {
                FormsAuthentication.RedirectToLoginPage();
                return null;
            }

            if ((!ModelState.IsValid || form.Mark == 0) && skipAnswerFeedback == false)
                return PartialView(MVC.Thread.Views.CreateFeedback, form);

            if (thread.State == ThreadState.Occupied || thread.State == ThreadState.Reserved)
            {
                thread.State = ThreadState.Accepted;
                thread.ThreadAcceptanceDate = DateTime.Now;
                thread.HandleProvisions();
            }

            Repository.Thread.Update(thread);

            //zwolnienie płatności wstępnej
            thread.AddTransfer(Transfer.Pending(thread.Value, string.Format(Resources.Payment.TransferThreadPaymentPendingReleaseText, thread.Name)), AuthenticationHelper.CurrentUser);
            //pobranie płatności końcowej
            thread.AddTransfer(Transfer.Cash(-thread.Value, string.Format(Resources.Payment.TransferAcceptAnswerFeeText, thread.Name)), AuthenticationHelper.CurrentUser);
            //wypłata wynagrodzenia dla eksperta z tytułu akceptacji
            thread.AddTransfer(Transfer.Cash(thread.FullExpertProvisionValue(), string.Format(Resources.Payment.TransferAcceptAnswerExpertProvisionText, thread.Name)), thread.Expert.User);

            //wypłata prowizji dla pośrednika
            if (thread.BrokerProvision > decimal.Zero)
            {
                thread.AddTransfer(Transfer.Cash(thread.BrokerProvisionValue(), string.Format(Resources.Payment.TransferAcceptAnswerBrokerProvisionText, thread.Name)), thread.Broker);
                Repository.User.Update(thread.Broker);
            }

            if (thread.Expert.Recommendation != null && thread.Expert.AcceptedAnswers >= 4)
            {
                if (thread.Expert.Recommendation.Recommender != null && thread.Expert.Recommendation.DidRecommenderReceiveBonus == false)
                {
                    var transfer = new Transfer
                    {
                        OrderDate = DateTime.Now,
                        TransferDate = DateTime.Now,
                        Title = Resources.Payment.RecommenderBonus,
                        Payment = null,
                        Value = 20,
                        IsPending = false,
                        Owner = thread.Expert.Recommendation.Recommender
                    };
                    thread.Expert.Recommendation.DidRecommenderReceiveBonus = true;

                    Repository.Transfer.Add(transfer);
                    Repository.Transfer.Update(transfer);
                    Repository.Recommendation.Update(thread.Expert.Recommendation);
                }
            }

            Repository.Thread.Update(thread);
            Repository.User.Update(AuthenticationHelper.CurrentUser);
            Repository.User.Update(thread.Expert.User);

            Email.Send<ThreadAnswerAcceptedEmail>(thread);
            EventLog.Event<AuthorAcceptedAnswerEvent>(thread, thread.Expert.PublicName);

            Flash.Success(Resources.Thread.AnswerAccepted);

            if(!skipAnswerFeedback)
            {
                var feedback = Mapper.Map<Feedback>(form);
                Repository.Thread.AddFeedback(thread, feedback);
                Repository.Expert.UpdateExpertStats(thread.Expert);
                Repository.User.UpdateUserStats(thread.Author);

                Flash.Success(Resources.Thread.FeedbackAdded);
                EventLog.Event<AuthorCreatedFeedbackEvent>(thread, thread.Expert.PublicName);
            }

            return null;
        }
Ejemplo n.º 2
0
        public virtual ActionResult Payoff(PayoffForm form)
        {
            var user = AuthenticationHelper.CurrentUser;

            if (!ModelState.IsValid)
                return PartialView(MVC.Profile.Views.PayoffForm, form);

            if (form.PayoffValue == decimal.Zero) return null;

            var availableCash = user.GetAvailableCash();
            if (availableCash < form.PayoffValue)
            {
                ModelState.AddModelError("PayoffValue",string.Format(Resources.Account.PayoffValueToHigh,availableCash));
                form.PayoffValue = availableCash;
                return PartialView(MVC.Profile.Views.PayoffForm,form);
            }

            var transfer = new Transfer
                               {
                                   Value = -form.PayoffValue.Value,
                                   Title = Resources.Payment.TransferCashPayoff,
                                   OrderDate = DateTime.Now,
                                   TransferDate = null,
                                   Payment = null,
                                   IsPending = false,
                                   Comment = null
                               };
            
            //AuthenticationHelper.CurrentUser.Transfers.Add(Transfer.Cash(-form.PayoffValue.Value, Resources.Payment.TransferCashPayoff, isTransfered: false));
            //AuthenticationHelper.CurrentUser.BankAccountNumber = form.BankAccount;
            user.Transfers.Add(transfer);
            user.BankAccountNumber = form.BankAccount;

            Repository.User.Update(AuthenticationHelper.CurrentUser);

            Email.Send<UserPayoffConfirmationEmail>(user);

            EventLog.Event<CashPaymentEvent>(user, additionalId: transfer.Id);

            Flash.Success(string.Format(Resources.Payment.FlashPayoffOrderSuccess, form.PayoffValue,form.BankAccount));

            return null;
        }
Ejemplo n.º 3
0
 public static void AddTransfer(this IService service, Transfer transfer, User buyer)
 {
     service.Transfers.Add(transfer);
     buyer.Transfers.Add(transfer);
 }