예제 #1
0
        public async Task <IActionResult> Create(LiverViewModel model)
        {
            if (!_permissions.IsAdmin())
            {
                return(this.NotFound());
            }
            if (ModelState.IsValid)
            {
                var Liver = new Liver()
                {
                    ChannelId   = model.ChannelId,
                    Name        = model.Name,
                    Graduated   = model.Graduated,
                    GroupId     = model.GroupId,
                    TwitterLink = model.TwitterLink
                };
                if (await AddLiverInfo(Liver))
                {
                    _context.Add(Liver);
                    await _context.SaveChangesAsync();

                    return(this.RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("ChannelId", "Make sure channel's Id is correct!");
                }
            }
            ViewBag.Groups = new SelectList(await _context.Groups.ToListAsync(), "Id", "Name", model.GroupId);
            return(this.View(model));
        }
예제 #2
0
        public async Task <IActionResult> Edit(Int32 id, LiverViewModel model)
        {
            if (!_permissions.IsAdmin())
            {
                return(this.NotFound());
            }
            var Liver = await _context.Livers.SingleOrDefaultAsync(_liver => _liver.Id == id);

            if (Liver == null)
            {
                return(this.NotFound());
            }
            if (ModelState.IsValid)
            {
                Liver.GroupId     = model.GroupId;
                Liver.Name        = model.Name;
                Liver.Graduated   = model.Graduated;
                Liver.TwitterLink = model.TwitterLink;
                await _context.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }
            ViewBag.Groups = new SelectList(await _context.Groups.ToListAsync(), "Id", "Name", model.GroupId);
            return(this.View(model));
        }