public async Task <IActionResult> Edit(int id, [Bind("Id,ApplicationUserId,Name,ShortName,BgImage,Logo,Description,CreationDate,CommunityType,SpecialityId,SecurityLevel,IsCommentsAllowed,IsFeatured,IsApproved,IsSuspended,Tags")] Community community, IFormFile myfile, IFormFile myfile1)
        {
            if (id != community.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    community.ApplicationUserId = _userManager.GetUserId(User);
                    community.BgImage           = await UserFile.UploadImageResizeTo(community.BgImage,
                                                                                     myfile, _environment.WebRootPath, Properties.Resources.Community, 1145, 330);

                    community.Logo = await UserFile.UploadImageResizeTo(community.Logo,
                                                                        myfile1, _environment.WebRootPath, Properties.Resources.Community, 100, 100);

                    community.CreationDate      = DateTime.Now;
                    community.IsFeatured        = false;
                    community.IsSuspended       = false;
                    community.IsApproved        = false;
                    community.IsCommentsAllowed = true;
                    community.SecurityLevel     = SecurityLevel.Open;
                    community.CommunityType     = CommunityType.Personal;
                    _context.Update(community);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommunityExists(community.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", community.ApplicationUserId);
            ViewData["SpecialityId"]      = new SelectList(_context.Specialities, "Id", "Name", community.SpecialityId);
            return(View(community));
        }
        public async Task <IActionResult> Create([Bind("Id,ApplicationUserId,Name,ShortName,BgImage,Logo,Description,CreationDate,CommunityType,SpecialityId,SecurityLevel,IsCommentsAllowed,IsFeatured,IsApproved,IsSuspended,Tags")] Community community, IFormFile myfile, IFormFile myfile1)
        {
            if (ModelState.IsValid)
            {
                community.ApplicationUserId = _userManager.GetUserId(User);
                community.BgImage           = await UserFile.UploadImageResizeTo(community.BgImage,
                                                                                 myfile, _environment.WebRootPath, Properties.Resources.Community, 400, 150);

                community.Logo = await UserFile.UploadImageResizeTo(community.Logo,
                                                                    myfile1, _environment.WebRootPath, Properties.Resources.Community, 100, 100);

                community.CreationDate      = DateTime.Now;
                community.IsFeatured        = false;
                community.IsSuspended       = false;
                community.IsApproved        = false;
                community.IsCommentsAllowed = true;
                community.SecurityLevel     = SecurityLevel.Open;
                community.CommunityType     = CommunityType.Personal;
                _context.Add(community);
                await _context.SaveChangesAsync();

                try
                {
                    var ApplicationUser = _context.Communities.Include(c => c.ApplicationUser).SingleOrDefault(a => a.Id == community.Id).ApplicationUser;

                    EmailContent content2 = _context.EmailContents.Where(m => m.UniqueName.ToString() == "fbfefb8b-1037-4fbc-ae85-765a99e63e5a").SingleOrDefault();
                    BackgroundJob.Schedule(() => _emailSender.SendEmailAsync(ApplicationUser.Email, content2.ArSubject, content2.ArContent), TimeSpan.FromMinutes(1));
                }
                catch (Exception)
                {
                    return(RedirectToAction(nameof(Index), new { id = community.Id }));
                }


                return(RedirectToAction(nameof(Index), new { id = community.Id }));
            }
            //ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", community.ApplicationUserId);
            ViewData["SpecialityId"] = new SelectList(_context.Specialities, "Id", "Name", community.SpecialityId);
            return(View(community));
        }