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; }
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; }
public ActionResult New() { var model = new VariantEditModel(); return View("Edit", model); }