Exemplo n.º 1
0
        public ActionResult Publication(Publication a)
        {
            Dictionary <string, string> errors = a.CheckForValidity();
            var matchingCiteKeys = (from pubs in DataPersistence.GetSession().Linq <Publication>()
                                    where pubs.CiteKey.Equals(a.CiteKey)
                                    select pubs);
            int ckCount = matchingCiteKeys.Count();

            if (ckCount > 0 && a.Id == 0)
            {
                string       linkToOther = "";// "<a href=\"Publication/" + matchingCiteKeys.First().Id + "\" target=\"_blank\">Click here to open the clash in a new window</a>";
                const string ckKey       = "CiteKey";
                if (errors.ContainsKey(ckKey))
                {
                    errors[ckKey] += ". " + ErrorMessages.CiteKeyNotUnique + " " + linkToOther;
                }
                errors.Add(ckKey, ErrorMessages.CiteKeyNotUnique + " " + linkToOther);
            }
            // there are no errors if this is the case)
            if (errors.Count == 0 && ModelState.IsValid)
            {
                a.Owner = HttpContext.User.Identity.Name;
                a.SaveOrUpdateInDatabase();
                return(Redirect("~/Entry"));
            }
            foreach (KeyValuePair <string, string> kvp in errors)
            {
                ModelState.AddModelError(kvp.Key, kvp.Value);
            }
            return(View(a));
        }