public static void RemoveVote(Translation translation)
        {
            var voter = TranslatorService.FindByEmail(HttpContext.Current.User.Identity.Name);
            var vote  = FindVote(translation, voter);

            if (vote != null)
            {
                if (vote.IsPublished == false)
                {
                    Global.CurrentSession.Delete(vote);
                }
            }
        }
        public static void Vote(Translation translation)
        {
            var voter = TranslatorService.FindByEmail(HttpContext.Current.User.Identity.Name);
            var vote  = FindVote(translation, voter);

            if (vote == null)
            {
                vote = new TranslationVote()
                {
                    CreatedAt   = DateTime.UtcNow,
                    IsPublished = false,
                    Rank        = voter.Rank,
                    Translation = translation,
                    Translator  = voter
                };

                Global.CurrentSession.Save(vote);
            }
        }
Beispiel #3
0
        public static Translation UpdateTranslation(int id, string language, string value)
        {
            string emailAddress = HttpContext.Current.User.Identity.Name;
            var    translator   = TranslatorService.FindByEmail(emailAddress);
            var    translation  = TranslationService.FindByKeyForTranslator(id, language, translator);
            var    leading      = TranslationService.FindByKey(id, language);

            if (translation != null)
            {
                if (leading != null && leading.Value == value)
                {
                    Global.CurrentSession.Delete(translation);
                }
                else
                {
                    translation.Value = value;

                    Global.CurrentSession.Update(translation);
                }
            }
            else if (!string.IsNullOrWhiteSpace(value))
            {
                if (leading == null || value != leading.Value)
                {
                    translation             = new Translation();
                    translation.Key         = Global.CurrentSession.Load <TranslateKey>(id);
                    translation.Language    = LanguageService.GetLanguageByIsoCode(language);
                    translation.Value       = value;
                    translation.IsPublished = false;
                    translation.Translator  = TranslatorService.FindByEmail(emailAddress);

                    Global.CurrentSession.Save(translation);
                }
                else
                {
                    translation = leading;
                }
            }
            return(translation);
        }