Ejemplo n.º 1
0
        public ActionResult AddMember(Guid id, AddMemberViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                return View(model);
            }

            var db = this.DB();
            var account = db.Accounts.FirstOrDefault(_ => _.AccountName == model.Name && _.ProviderName == model.Provider);
            if (account == null)
            {
                account = new Account
                {
                    AccountName = model.Name,
                    ProviderName = model.Provider
                };
                db.Accounts.Add(account);
                db.SaveChanges();
            }

            var channel = this.DB().Channels.Find(id);
            if (channel.ChannelMembers.Any(_ => _.AccountId == account.Id))
            {
                ModelState.AddModelError("Name", "This account is already member of this channel.");
                return View(model);
            }

            channel.ChannelMembers.Add(new ChannelMember
            {
                AccountId = account.Id,
                IsOwner = model.IsOwner
            });
            db.SaveChanges();

            return RedirectToAction("Settings", new { id });
        }
Ejemplo n.º 2
0
 public ActionResult AddMember(Guid id)
 {
     var model = new AddMemberViewModel();
     return View(model);
 }