Beispiel #1
0
        public string RenameTribe(Session session, String[] parms)
        {
            bool   help         = false;
            string tribeName    = string.Empty;
            string newTribeName = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                    { "newname=", v => newTribeName = v.TrimMatchingQuotes() }
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(tribeName) || string.IsNullOrEmpty(newTribeName))
            {
                return("renametribe --tribe=name --newname=name");
            }

            uint tribeId;

            if (!tribeManager.FindTribeId(tribeName, out tribeId))
            {
                return("Tribe not found");
            }

            ITribe tribe;

            return(locker.Lock(tribeId, out tribe).Do(() =>
            {
                if (tribe == null)
                {
                    return "Tribe not found";
                }

                if (!Tribe.IsNameValid(newTribeName))
                {
                    return "New tribe name is not allowed";
                }

                if (tribeManager.TribeNameTaken(newTribeName))
                {
                    return "New tribe name is already taken";
                }

                tribe.Name = newTribeName;
                dbManager.Save(tribe);

                return "OK!";
            }));
        }