public ActionResult Edit(int id, [Bind(Include = "Name,NumPlayers,Description,HelpText")] VariantEditModel model)
        {
            var variant = Entities().Variants.Find(id);

            if (variant == null)
            {
                return(HttpNotFound());
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", new { id = id }));
            }

            UserService users = GetService <UserService>();

            if (!users.IsAllowedToEdit(variant, User.Identity.Name))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!ValidateName(model, variant))
            {
                return(View(model));
            }

            variant.Description = model.Description ?? string.Empty;
            variant.HelpText    = DataService.StripTags(model.HelpText ?? string.Empty);

            Entities().SaveChanges();

            return(RedirectToAction("Edit", new { id = id }));
        }
Beispiel #2
0
        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);
        }
        public ActionResult VariantEdit(VariantEditModel model)
        {
            var variant = db.Variants.Find(model.VariantId);

            if (variant != null)
            {
                variant.Name      = model.VariantName;
                variant.UnitPrice = model.UnitPrice;
                variant.Stock     = model.Stock;
                variant.IsVisible = model.IsVisible;
                variant.Cost      = model.Cost;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index", new { Error = "Variant Not Found" }));
            }
        }
        public ActionResult VariantEdit(Int64 id)
        {
            var variant = db.Variants.Find(id);

            if (variant != null)
            {
                var model = new VariantEditModel();
                model.ProductId   = variant.ProductId;
                model.VariantId   = variant.VariantId;
                model.VariantName = variant.Name;
                model.UnitPrice   = variant.UnitPrice;
                model.Stock       = variant.Stock;
                model.IsVisible   = variant.IsVisible;
                model.Cost        = variant.Cost;

                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", new { Error = "Variant Not Found" }));
            }
        }
        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([Bind(Include = "Name,NumPlayers,Description,HelpText")] VariantEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("New"));
            }

            UserService    users    = GetService <UserService>();
            VariantService variants = GetService <VariantService>();

            var user = users.GetByName(User.Identity.Name);

            var variant = new Variant();

            variant.CreatedByID = user.ID;
            variant.Description = model.Description ?? string.Empty;
            variant.HelpText    = DataService.StripTags(model.HelpText ?? string.Empty);
            variant.PlayerCount = (byte)model.NumPlayers;

            if (!ValidateName(model, variant))
            {
                return(View(model));
            }

            var version = new VariantVersion();

            version.Number       = 1;
            version.LastModified = DateTime.Now;
            version.Variant      = variant;
            version.Definition   = string.Empty;

            Entities().Variants.Add(variant);
            Entities().VariantVersions.Add(version);
            Entities().SaveChanges();

            return(RedirectToAction("Shape", "Designer", new { version.ID }));
        }
        public ActionResult New()
        {
            var model = new VariantEditModel();

            return(View("Edit", model));
        }