public ActionResult Redeem(string code)
        {
            var db = new ZkDataContext();

            if (string.IsNullOrEmpty(code))
            {
                return(Content("Code is empty"));
            }
            var contrib = db.Contributions.SingleOrDefault(x => x.RedeemCode == code);

            if (contrib == null)
            {
                return(Content("No contribution with that code found"));
            }
            if (contrib.AccountByAccountID != null)
            {
                return(Content(string.Format("This contribution has been assigned to {0}, thank you.", contrib.AccountByAccountID.Name)));
            }
            var acc = Account.AccountByAccountID(db, Global.AccountID);

            contrib.AccountByAccountID = acc;
            db.SubmitAndMergeChanges();
            acc.Kudos = acc.KudosGained - acc.KudosSpent;
            db.SubmitAndMergeChanges();

            return(Content(string.Format("Thank you!! {0} Kudos have been added to your account {1}", contrib.KudosValue, contrib.AccountByAccountID.Name)));
        }
        public ActionResult AddContribution(int accountID, int kudos, string item, string currency, double gross, double grossEur, double netEur, string email, string comment, bool isSpring, DateTime date)
        {
            using (var db = new ZkDataContext()) {
                var acc     = Account.AccountByAccountID(db, accountID);
                var contrib = new Contribution()
                {
                    AccountID = accountID,
                    ManuallyAddedAccountID = Global.AccountID,
                    KudosValue             = kudos,
                    ItemName             = item,
                    IsSpringContribution = isSpring,
                    Comment          = comment,
                    OriginalCurrency = currency,
                    OriginalAmount   = gross,
                    Euros            = grossEur,
                    EurosNet         = netEur,
                    Time             = date,
                    Name             = acc.Name,
                    Email            = email
                };
                db.Contributions.InsertOnSubmit(contrib);
                db.SubmitAndMergeChanges();
                acc.Kudos = acc.KudosGained - acc.KudosSpent;
                db.SubmitAndMergeChanges();
            }


            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public ActionResult ReportToAdmin(int id)
        {
            var db  = new ZkDataContext();
            var acc = Account.AccountByAccountID(db, id);

            return(View("ReportToAdmin", acc));
        }
Esempio n. 4
0
        public ActionResult AdminUserDetail(int id)
        {
            var db   = new ZkDataContext();
            var user = Account.AccountByAccountID(db, id);

            return(View("AdminUserDetail", user));
        }
Esempio n. 5
0
        public ActionResult Unlock(int id, bool useKudos = false)
        {
            using (var db = new ZkDataContext())
                using (var scope = new TransactionScope())
                {
                    List <Unlock> unlocks;
                    List <Unlock> future;

                    GetUnlockLists(db, out unlocks, out future);

                    if (unlocks.Any(x => x.UnlockID == id))
                    {
                        Unlock unlock = db.Unlocks.FirstOrDefault(x => x.UnlockID == id);
                        if (!useKudos && unlock.IsKudosOnly == true)
                        {
                            return(Content("That unlock cannot be bought using XP"));
                        }

                        if (useKudos)
                        {
                            var acc = Account.AccountByAccountID(db, Global.AccountID);
                            if (acc.Kudos < unlock.KudosCost)
                            {
                                return(Content("Not enough kudos to unlock this"));
                            }
                            acc.KudosPurchases.Add(new KudosPurchase()
                            {
                                Time = DateTime.UtcNow, Unlock = unlock, Account = acc, KudosValue = unlock.KudosCost ?? 0
                            });
                            db.SubmitAndMergeChanges();
                            acc.Kudos = acc.KudosGained - acc.KudosSpent;
                            db.SubmitAndMergeChanges();
                        }

                        var au = db.AccountUnlocks.SingleOrDefault(x => x.AccountID == Global.AccountID && x.UnlockID == id);
                        if (au == null)
                        {
                            au = new AccountUnlock()
                            {
                                AccountID = Global.AccountID, UnlockID = id, Count = 1
                            };
                            db.AccountUnlocks.InsertOnSubmit(au);
                        }
                        else
                        {
                            au.Count++;
                        }
                        db.SubmitAndMergeChanges();
                    }
                    scope.Complete();
                }
            return(RedirectToAction("UnlockList"));
        }
Esempio n. 6
0
        public ActionResult Detail(string id)
        {
            var db = new ZkDataContext();

            int     idint;
            Account user = null;

            if (int.TryParse(id, out idint))
            {
                user = Account.AccountByAccountID(db, idint);
            }
            if (user == null)
            {
                user = Account.AccountByName(db, id);
            }
            return(View("UserDetail", user));
        }
Esempio n. 7
0
        public ActionResult ReportToAdminSubmit(int accountID, string text)
        {
            var db  = new ZkDataContext();
            var acc = Account.AccountByAccountID(db, accountID);

            db.AbuseReports.InsertOnSubmit(new AbuseReport()
            {
                AccountID         = acc.AccountID,
                ReporterAccountID = Global.AccountID,
                Time = DateTime.UtcNow,
                Text = text
            });
            db.SubmitAndMergeChanges();

            var str = string.Format("{0} {1} reports abuse by {2} {3} : {4}", Global.Account.Name, Url.Action("Detail", "Users", new { id = Global.AccountID }, "http"), acc.Name, Url.Action("Detail", "Users", new { id = acc.AccountID }, "http"), text);

            Global.Nightwatch.Tas.Say(TasClient.SayPlace.Channel, AuthService.ModeratorChannel, str, true);
            foreach (var u in Global.Nightwatch.Tas.JoinedChannels[AuthService.ModeratorChannel].ChannelUsers)
            {
                Global.Nightwatch.Tas.Ring(u);
            }

            return(Content("Thank you. Your issue was reported. Moderators will now look into it."));
        }
        Contribution AddPayPalContribution(ParsedData parsed)
        {
            try {
                if ((parsed.Status != "Completed" && parsed.Status != "Cleared") || parsed.Gross <= 0)
                {
                    return(null);                                                                                   // not a contribution!
                }
                double netEur;
                double grossEur;
                if (parsed.Currency == "EUR")
                {
                    netEur   = parsed.Net;
                    grossEur = parsed.Gross;
                }
                else
                {
                    netEur   = ConvertToEuros(parsed.Currency, parsed.Net);
                    grossEur = ConvertToEuros(parsed.Currency, parsed.Gross);
                }

                int?accountID, jarID;
                TryParseItemCode(parsed.ItemCode, out accountID, out jarID);

                Contribution contrib;
                using (var db = new ZkDataContext()) {
                    Account         acc = null;
                    ContributionJar jar;
                    if (jarID == null)
                    {
                        jar = db.ContributionJars.FirstOrDefault(x => x.IsDefault);
                    }
                    else
                    {
                        jar = db.ContributionJars.FirstOrDefault(x => x.ContributionJarID == jarID);
                    }

                    if (accountID != null)
                    {
                        acc = Account.AccountByAccountID(db, accountID.Value);
                    }

                    if (!string.IsNullOrEmpty(parsed.TransactionID) && db.Contributions.Any(x => x.PayPalTransactionID == parsed.TransactionID))
                    {
                        return(null);                                                                                                                         // contribution already exists
                    }
                    var isSpring = !parsed.ItemCode.StartsWith("ZK") || jar.IsDefault;


                    contrib = new Contribution()
                    {
                        AccountByAccountID = acc,
                        Name                 = parsed.Name,
                        Euros                = grossEur,
                        KudosValue           = (int)Math.Round(grossEur * GlobalConst.EurosToKudos),
                        OriginalAmount       = parsed.Gross,
                        OriginalCurrency     = parsed.Currency,
                        PayPalTransactionID  = parsed.TransactionID,
                        ItemCode             = parsed.ItemCode,
                        Time                 = parsed.Time,
                        EurosNet             = netEur,
                        ItemName             = parsed.ItemName,
                        Email                = parsed.Email,
                        RedeemCode           = Guid.NewGuid().ToString(),
                        IsSpringContribution = isSpring,
                        ContributionJar      = jar
                    };
                    db.Contributions.InsertOnSubmit(contrib);

                    db.SubmitChanges();

                    if (acc != null)
                    {
                        acc.Kudos = acc.KudosGained - acc.KudosSpent;
                    }
                    db.SubmitAndMergeChanges();


                    // technically not needed to sent when account is known, but perhaps its nice to get a confirmation like that

                    SendEmail(contrib);

                    NewContribution(contrib);
                }

                return(contrib);
            } catch (Exception ex) {
                Trace.TraceError("Error processing payment: {0}", ex);
                Error(ex.ToString());
                return(null);
            }
        }
Esempio n. 9
0
        public ActionResult ModifyTreaty(int factionTreatyID,
                                         int?turns,
                                         int?acceptingFactionID,
                                         int?effectTypeID,
                                         double?effectValue,
                                         int?planetID,
                                         bool?isReverse,
                                         string note,
                                         string add, int?delete, string propose)
        {
            if (!Global.Account.HasFactionRight(x => x.RightDiplomacy))
            {
                return(Content("Not a diplomat!"));
            }

            FactionTreaty treaty;

            // submit, store treaty in db
            var db = new ZkDataContext();

            if (factionTreatyID > 0)
            {
                treaty = db.FactionTreaties.Single(x => x.FactionTreatyID == factionTreatyID);
                if (treaty.TreatyState != TreatyState.Invalid)
                {
                    return(Content("Treaty already in progress!"));
                }
            }
            else
            {
                treaty = new FactionTreaty();
                db.FactionTreaties.InsertOnSubmit(treaty);
                treaty.FactionByAcceptingFactionID = db.Factions.Single(x => x.FactionID == acceptingFactionID);
            }
            treaty.AccountByProposingAccountID = Account.AccountByAccountID(db, Global.AccountID);
            treaty.FactionByProposingFactionID = db.Factions.Single(x => x.FactionID == Global.FactionID);
            treaty.TurnsRemaining = turns;
            treaty.TurnsTotal     = turns;
            treaty.TreatyNote     = note;


            if (!string.IsNullOrEmpty(add))
            {
                TreatyEffectType effectType = db.TreatyEffectTypes.Single(x => x.EffectTypeID == effectTypeID);
                var effect = new TreatyEffect
                {
                    FactionByGivingFactionID    = isReverse == true ? treaty.FactionByAcceptingFactionID : treaty.FactionByProposingFactionID,
                    FactionByReceivingFactionID =
                        isReverse == true ? treaty.FactionByProposingFactionID : treaty.FactionByAcceptingFactionID,
                    TreatyEffectType = effectType,
                    FactionTreaty    = treaty
                };
                if (effectType.HasValue)
                {
                    if (effectType.MinValue.HasValue && effectValue < effectType.MinValue.Value)
                    {
                        effectValue = effectType.MinValue;
                    }
                    if (effectType.MaxValue.HasValue && effectValue > effectType.MaxValue.Value)
                    {
                        effectValue = effectType.MaxValue;
                    }
                }
                if (effectType.HasValue)
                {
                    effect.Value = effectValue;
                }
                if (effectType.IsPlanetBased)
                {
                    effect.PlanetID = planetID.Value;
                }
                db.TreatyEffects.InsertOnSubmit(effect);
            }
            if (delete != null)
            {
                db.TreatyEffects.DeleteOnSubmit(db.TreatyEffects.Single(x => x.TreatyEffectID == delete));
            }
            db.SubmitAndMergeChanges();

            if (!string.IsNullOrEmpty(propose))
            {
                treaty.TreatyState = TreatyState.Proposed;

                db.Events.InsertOnSubmit(Global.CreateEvent("{0} proposes a new treaty between {1} and {2} - {3}", treaty.AccountByProposingAccountID, treaty.FactionByProposingFactionID, treaty.FactionByAcceptingFactionID, treaty));

                db.SubmitAndMergeChanges();
                return(RedirectToAction("Detail", new { id = treaty.ProposingFactionID }));
            }

            return(View("FactionTreatyDefinition", treaty));
        }