public ActionResult Create(OrganizationFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", viewModel));
            }
            var ownerId      = User.Identity.GetUserId();
            var organization = new Organization()
            {
                Name    = viewModel.Name,
                OwnerId = ownerId
            };

            _context.Organizations.Add(organization);

            var membership = new Membership()
            {
                MemberId       = ownerId,
                OrganizationId = organization.Id
            };

            _context.Memberships.Add(membership);
            _context.SaveChanges();

            return(RedirectToAction("MyOrganizations"));
        }
        public ActionResult OrganizationForm()
        {
            var viewModel = new OrganizationFormViewModel()
            {
                Organization = new Organization(),
                PageTitle    = "New"
            };

            return(View(viewModel));
        }
        public ActionResult Edit(int id)
        {
            var organizationInDb = _context.Organizations.SingleOrDefault(c => c.Id == id);

            var viewModel = new OrganizationFormViewModel
            {
                Organization = organizationInDb,
                PageTitle    = "Edit"
            };

            return(View("OrganizationForm", viewModel));
        }
 public ActionResult AddOrganization(Organization organization)
 {
     if (!ModelState.IsValid)
     {
         var viewModel = new OrganizationFormViewModel
         {
             Organization = organization,
             PageTitle    = "Edit"
         };
         return(View(viewModel));
     }
     if (organization.Id == 0)
     {
         _context.Organizations.Add(organization);
     }
     else
     {
         var organizationInDb = _context.Organizations.SingleOrDefault(c => c.Id == organization.Id);
         organizationInDb.Name = organization.Name;
     }
     _context.SaveChanges();
     return(RedirectToAction("Index", "Organization"));
 }
        public ActionResult Create()
        {
            var viewModel = new OrganizationFormViewModel();

            return(View(viewModel));
        }