public async Task<ActionResult> Create(Accreditation accreditation)
        {
            if (ModelState.IsValid)
            {
                db.Accreditations.Add(accreditation);
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            return View(accreditation);
        }
        public async Task<ActionResult> AccreditationFinish(Accreditation model, string slug)
        {
            using(var ctx = new SportDataContext()) {
                var userManager = new UserManager<User>(new UserStore<User>(ctx));
                var currentUser = await userManager.FindByIdAsync(User.Identity.GetUserId());

                model.User = currentUser;
                var ev = await EventService.GetEvent(slug, ctx); 

                var tag = ev.SubEvents.Select(s => s.Tag).First();                
                model.Tag = tag;

                tag.Accreditations.Add(model);
                await ctx.SaveChangesAsync();

                ViewBag.Slug = slug;
                ViewBag.EventName = ev.Title;

                EmailService.SendAdministrativeMail("Поступила заявка на аккредитацию на " + ev.Title,
                    @"Поступила заявка на аккредитацию на " + ev.Title + " от " + model.User.LastName + " " + model.User.FirstName + ". Пожалуйста перейдите по ссылке http://www.afspb.org.ru/controlpanel/accreditations/validate/" + model.Id + " для обработки заявки."); 

                return View();
            }
        }
        public async Task<ActionResult> Edit(Accreditation accreditation)
        {
            if (ModelState.IsValid)
            {
                accreditation.Valid = true;
                db.Entry(accreditation).State = EntityState.Modified;
                db.Entry(accreditation.User).State = EntityState.Modified;
                foreach(var media in accreditation.Media)
                    db.Entry(media).State = EntityState.Modified;

                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View(accreditation);
        }