コード例 #1
0
ファイル: VariantService.cs プロジェクト: rbanna01/Chessmaker
        public VariantEditModel CreateEditModel(Variant variant)
        {
            var model = new VariantEditModel(variant);

            var versions = variant.AllVersions.OrderByDescending(x => x.Number);
            foreach (var version in versions)
                model.Versions.Add(new VersionSelectionModel(version, version.ID == variant.PublicVersionID, CanDelete(version)));

            return model;
        }
コード例 #2
0
        private bool ValidateName(VariantEditModel model, Variant variant)
        {
            variant.Name = model.Name.Trim();

            var existing = Entities().Variants.SingleOrDefault(v => v.Name == variant.Name);
            if (existing != null && existing.ID != variant.ID)
            {
                ModelState.AddModelError("Name", "This name is not unique.");
                return false;
            }

            variant.Tag = GetService<VariantService>().GenerateTagName(variant.Name);

            existing = Entities().Variants.SingleOrDefault(v => v.Tag == variant.Tag);
            if (existing != null && existing.ID != variant.ID)
            {
                ModelState.AddModelError("Name", "The tag generated by this name is not unique. (" + variant.Tag + ")");
                return false;
            }
            return true;
        }
コード例 #3
0
 public ActionResult New()
 {
     var model = new VariantEditModel();
     return View("Edit", model);
 }