Exemplo n.º 1
0
        private static string ToHumanReadableHelper(NewspaperRightsEnum rights)
        {
            switch (rights)
            {
            case NewspaperRightsEnum.CanWriteArticles:
                return("can write articles");

            case NewspaperRightsEnum.CanManageArticles:
                return("can manage articles");

            case NewspaperRightsEnum.CanManageJournalists:
                return("can manage journalists");

            case NewspaperRightsEnum.CanSwitchInto:
                return("can switch into");

            case NewspaperRightsEnum.CanSeeWallet:
                return("can see wallet");

            case NewspaperRightsEnum.Full:
                return("full rights");

            case NewspaperRightsEnum.None:
                return("no rights");
            }
#if !DEBUG
            return(rights.ToString());
#else
            throw new NotImplementedException("ToHumanReadable NewspaperRightsEnum - " + rights.ToString());
#endif
        }
Exemplo n.º 2
0
        public void ChangeJournalistRights(int journalistID, int newspaperID, NewspaperRightsEnum rights)
        {
            var journalist = context.NewspaperJournalists.First(j => j.CitizenID == journalistID && j.NewspaperID == newspaperID);

            journalist.CanWriteArticles     = rights.HasFlag(NewspaperRightsEnum.CanWriteArticles);
            journalist.CanManageArticles    = rights.HasFlag(NewspaperRightsEnum.CanManageArticles);
            journalist.CanManageJournalists = rights.HasFlag(NewspaperRightsEnum.CanManageJournalists);
        }
Exemplo n.º 3
0
        private static string generateChangeRightsMessage(Newspaper newspaper, NewspaperRightsEnum oldRights, NewspaperRightsEnum newRights)
        {
            if (hasChanged(oldRights, newRights) == false)
            {
                return(null);
            }

            string message = string.Format("Your rights in {0} were changed. Your current rights: {1}", newspaper.Entity.Name, newRights.ToHumanReadable());

            if (message.Last() == ',')
            {
                message = message.Substring(0, message.Length - 1);
            }

            return(message + ".");
        }
Exemplo n.º 4
0
        public static string ToHumanReadable(this NewspaperRightsEnum rights)
        {
            if (rights == 0)
            {
                return("none");
            }

            string msg = "";

            foreach (NewspaperRightsEnum right in Enum.GetValues(typeof(NewspaperRightsEnum)))
            {
                if (right == 0 || right == NewspaperRightsEnum.Full)
                {
                    continue;
                }

                if (rights.HasFlag(right))
                {
                    msg += ToHumanReadableHelper(right) + ", ";
                }
            }

            return(msg.Substring(0, msg.Length - 2));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Does not support FULL enum
 /// </summary>
 private static bool hasChanged(NewspaperRightsEnum oldRights, NewspaperRightsEnum newRights)
 {
     return(oldRights != newRights);
 }