コード例 #1
0
        // GET: Guild/Edit/5
        public ActionResult GuildEdit(int?id)
        {
            var guild = m.GuildGetById(id.GetValueOrDefault());

            if (guild == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var form = new GuildEditLeaderForm();
                form.Name        = guild.Name;
                form.Description = guild.Description;
                form.Leader      = guild.Leader;
                form.LeaderId    = new SelectList(guild.Members, "Id", "Name", guild.Leader.Id);
                form.GameId      = guild.Game.Id;
                return(View(form));
            }
        }
コード例 #2
0
        public ActionResult GuildEdit(int?id, GuildEditLeaderInfo newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", new { id = newItem.Id }));
            }
            if (id.GetValueOrDefault() != newItem.Id)
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                var g = m.GuildgetByName(newItem.Name, newItem.GameId);
                if (g == null)
                {
                    var item = m.GuildEdit(newItem);
                    if (item != null)
                    {
                        return(RedirectToAction("Details", new { id = item.Id }));
                    }
                }
                var guild = m.GuildGetById(id.GetValueOrDefault());

                var form = new GuildEditLeaderForm();
                form.Name        = guild.Name;
                form.Description = guild.Description;
                form.Leader      = guild.Leader;
                form.LeaderId    = new SelectList(guild.Members, "Id", "Name", guild.Leader.Id);
                form.GameId      = guild.Game.Id;
                form.errorName   = "The name is already in use.";
                return(View(form));
            }
            catch (Exception e)
            {
            }
            return(HttpNotFound());
        }