示例#1
0
        public async Task <IActionResult> ChangePrimaryChapter(
            [Bind("MemberId,MemberChapterId")] ChangePrimaryChapterViewModel viewModel)
        {
            var currentName    = "None";
            var currentPrimary = await _context.MemberChapters.Include(mc => mc.Chapter).FirstOrDefaultAsync(mc => mc.ApplicationUserId == viewModel.MemberId && mc.IsPrimary);

            if (currentPrimary != null)
            {
                currentName = currentPrimary.Chapter.Name;
                currentPrimary.IsPrimary = false;
                _context.Update(currentPrimary);
            }

            var newPrimary = await _context.MemberChapters.Include(mc => mc.Chapter).FirstOrDefaultAsync(mc => mc.Id == viewModel.MemberChapterId);

            newPrimary.IsPrimary = true;
            _context.Update(newPrimary);

            var user = await _userManager.GetUserAsync(HttpContext.User);

            var memberNote = new ApplicationUserNote
            {
                Note = "Changed primary chapter from " + currentName
                       + " to " + newPrimary.Chapter.Name,
                ApplicationUserId = viewModel.MemberId,
                AddedBy           = user.FirstName + " " + user.LastName,
                WhenAdded         = DateTime.Now
            };

            _context.ApplicationUserNotes.Add(memberNote);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = viewModel.MemberId }));
        }
示例#2
0
        public async Task <IActionResult> LeaveChapterConfirmed([Bind("MemberChapterId")] int id)
        {
            var leavePrimaryText = "";
            var model            = _context.MemberChapters.FirstOrDefault(m => m.Id == id);

            if (model.IsPrimary)
            {
                leavePrimaryText = "Removed Primary chapter.";
            }
            model.WhenExpires = DateTime.Now;
            model.IsPrimary   = false;
            _context.Update(model);

            var chapter = await _context.Chapters.FirstOrDefaultAsync(c => c.Id == model.ChapterId);

            var user = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.User = user.FirstName + " " + user.LastName;

            var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == model.ApplicationUserId);

            var memberNote = new ApplicationUserNote
            {
                Note = "Removed from chapter " + chapter.Name + ". " + leavePrimaryText,
                ApplicationUserId = model.ApplicationUserId,
                AddedBy           = user.FirstName + " " + user.LastName,
                WhenAdded         = DateTime.Now
            };

            _context.ApplicationUserNotes.Add(memberNote);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.ApplicationUserId }));
        }
示例#3
0
        public async Task <IActionResult> AddChapter([Bind("ApplicationUserId,ChapterId,WhenJoined,WhenExpires")] MemberAddChapterViewModel viewModel)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var chapter = await _context.Chapters.FirstOrDefaultAsync(c => c.Id == viewModel.ChapterId);

            ViewBag.User = user.FirstName + " " + user.LastName;
            var model = new MemberChapter
            {
                ApplicationUserId = viewModel.ApplicationUserId,
                ChapterId         = viewModel.ChapterId,
                WhenJoined        = viewModel.WhenJoined,
                WhenExpires       = viewModel.WhenExpires
            };

            _context.Add(model);

            var note = new ApplicationUserNote
            {
                ApplicationUserId = viewModel.ApplicationUserId,
                AddedBy           = user?.FirstName + " " + user?.LastName,
                WhenAdded         = DateTime.Now,
                Note = "Joined chapter " + chapter.Name
            };

            _context.Add(note);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = viewModel.ApplicationUserId }));
        }
示例#4
0
        public async Task <IActionResult> Renew(string MemberId, List <int> item_IsRenewal, List <int> item_ItemId, List <DateTime> item_NewWhenExpires)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var member = await _context.ApplicationUser.FindAsync(MemberId);

            var chapters = await _context.Chapters.ToListAsync();

            for (var i = 0; i < item_IsRenewal.Count; i++)
            {
                if (item_IsRenewal[i] == 1)
                {
                    if (item_ItemId[i] == 0)
                    {
                        member.WhenExpires = item_NewWhenExpires[i];
                        // TODO Change WhenLastRenewalSent to nullable
                        // member.WhenLastRenewalSent = null;
                        _context.Update(member);

                        var note = new ApplicationUserNote
                        {
                            ApplicationUserId = MemberId,
                            AddedBy           = user?.FirstName + " " + user?.LastName,
                            WhenAdded         = DateTime.Now,
                            Note = "Renewed league membership."
                        };
                        _context.Add(note);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        var memberChapter = await _context.MemberChapters.FindAsync(item_ItemId[i]);

                        memberChapter.WhenExpires         = item_NewWhenExpires[i];
                        memberChapter.WhenLastRenewalSent = null;
                        _context.Update(memberChapter);

                        var chapter = chapters.FirstOrDefault(c => c.Id == memberChapter.ChapterId);

                        var note = new ApplicationUserNote
                        {
                            ApplicationUserId = MemberId,
                            AddedBy           = user?.FirstName + " " + user?.LastName,
                            WhenAdded         = DateTime.Now,
                            Note = "Renewed chapter " + chapter.Name + "membership."
                        };
                        _context.Add(note);
                        await _context.SaveChangesAsync();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
示例#5
0
        public async Task <IActionResult> AddNote([Bind("ApplicationUserId,Text")] MemberNoteViewModel viewModel)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.User = user.FirstName + " " + user.LastName;

            var model = new ApplicationUserNote
            {
                ApplicationUserId = viewModel.ApplicationUserId,
                AddedBy           = user?.FirstName + " " + user?.LastName,
                WhenAdded         = DateTime.Now,
                Note = viewModel.Text
            };

            _context.Add(model);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = viewModel.ApplicationUserId }));
        }
示例#6
0
        public async Task <IActionResult> Edit([Bind("Id,City,Email,FirstName,LastName,State,Street1,Street2,Zip,Phone,Email,Note,WhenJoined,WhenExpires,Status,Chapter1,Chapter2")] MemberEditViewModel viewModel)
        {
            var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == viewModel.Id);

            if (viewModel.Id != applicationUser.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    applicationUser.City        = viewModel.City;
                    applicationUser.Email       = viewModel.Email;
                    applicationUser.FirstName   = viewModel.FirstName;
                    applicationUser.LastName    = viewModel.LastName;
                    applicationUser.Street1     = viewModel.Street1;
                    applicationUser.Street2     = viewModel.Street2;
                    applicationUser.City        = viewModel.City;
                    applicationUser.State       = viewModel.State;
                    applicationUser.ZipCode     = viewModel.Zip;
                    applicationUser.Email       = viewModel.Email;
                    applicationUser.PhoneNumber = viewModel.Phone;
                    applicationUser.Status      = viewModel.Status;
                    applicationUser.WhenJoined  = viewModel.WhenJoined;
                    applicationUser.WhenExpires = viewModel.WhenExpires;
                    _context.Update(applicationUser);
                    await _context.SaveChangesAsync();

                    if (!string.IsNullOrEmpty(viewModel.Note))
                    {
                        var note = new ApplicationUserNote
                        {
                            ApplicationUserId = applicationUser.Id,
                            WhenAdded         = DateTime.Now,
                            Note = viewModel.Note
                        };
                        _context.Add(note);
                        await _context.SaveChangesAsync();
                    }

                    var memberChapters = _context.MemberChapters
                                         .Where(m => m.ApplicationUserId == viewModel.Id && m.WhenLeft == null).ToList();
                    foreach (var mc in memberChapters)
                    {
                        if (!(mc.ChapterId == viewModel.Chapter1 || mc.ChapterId == viewModel.Chapter2))
                        {
                            mc.WhenLeft = DateTime.Now;
                        }
                    }
                    if (viewModel.Chapter1 != 0)
                    {
                        if (!memberChapters.Any(m => m.ChapterId == viewModel.Chapter1))
                        {
                            _context.Add(new MemberChapter
                            {
                                ApplicationUserId = viewModel.Id,
                                ChapterId         = viewModel.Chapter1,
                                WhenJoined        = DateTime.Now
                            });
                        }
                    }
                    if (viewModel.Chapter2 != 0)
                    {
                        if (!memberChapters.Any(m => m.ChapterId == viewModel.Chapter2))
                        {
                            _context.Add(new MemberChapter
                            {
                                ApplicationUserId = viewModel.Id,
                                ChapterId         = viewModel.Chapter2,
                                WhenJoined        = DateTime.Now
                            });
                        }
                    }
                    await _context.SaveChangesAsync();

                    Response.Cookies.Append("FlashSuccess", "Member " + applicationUser.FirstName + " " + applicationUser.LastName + " was successfully saved");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ApplicationUserExists(applicationUser.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }

            var chapterSelect = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "0", Text = "None"
                }
            };
            var chapters = await _context.Chapters.OrderBy(c => c.Name).ToListAsync();

            foreach (var chapter in chapters)
            {
                chapterSelect.Add(new SelectListItem
                {
                    Value = chapter.Id.ToString(),
                    Text  = chapter.Name
                });
            }
            viewModel.Chapters = chapterSelect;
            return(View(applicationUser));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("City,Email,FirstName,LastName,State,Street1,Street2,Zip,Phone,Email,Note,WhenJoined,WhenExpires,Status,Chapter1,Chapter2")] MemberCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var applicationUser = new ApplicationUser
                {
                    City        = viewModel.City,
                    Email       = viewModel.Email,
                    FirstName   = viewModel.FirstName,
                    LastName    = viewModel.LastName,
                    State       = viewModel.State,
                    Street1     = viewModel.Street1,
                    ZipCode     = viewModel.Zip,
                    PhoneNumber = viewModel.Phone,
                    WhenJoined  = viewModel.WhenJoined,
                    WhenExpires = viewModel.WhenExpires,
                    Status      = viewModel.Status
                };
                _context.Add(applicationUser);
                await _context.SaveChangesAsync();

                if (!string.IsNullOrEmpty(viewModel.Note))
                {
                    var note = new ApplicationUserNote
                    {
                        ApplicationUserId = applicationUser.Id,
                        WhenAdded         = DateTime.Now,
                        Note = viewModel.Note
                    };
                    _context.Add(note);
                }

                if (viewModel.Chapter1 != 0)
                {
                    _context.Add(new MemberChapter
                    {
                        ApplicationUserId = applicationUser.Id,
                        ChapterId         = viewModel.Chapter1,
                        WhenJoined        = DateTime.Now
                    });
                }
                if (viewModel.Chapter2 != 0)
                {
                    _context.Add(new MemberChapter
                    {
                        ApplicationUserId = applicationUser.Id,
                        ChapterId         = viewModel.Chapter2,
                        WhenJoined        = DateTime.Now
                    });
                }
                await _context.SaveChangesAsync();

                Response.Cookies.Append("FlashSuccess", "Member " + applicationUser.FirstName + " " + applicationUser.LastName + " was successfully saved");
                return(RedirectToAction("Index"));
            }
            var chapterSelect = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "0", Text = "None"
                }
            };
            var chapters = _context.Chapters.OrderBy(c => c.Name).ToList();

            foreach (var chapter in chapters)
            {
                chapterSelect.Add(new SelectListItem
                {
                    Value = chapter.Id.ToString(),
                    Text  = chapter.Name
                });
            }
            viewModel.Chapters = chapterSelect;

            return(View(viewModel));
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("City,Email,FirstName,LastName,State,Street1,Street2,Zip,Phone,Email,Note,WhenJoined,WhenExpires,Chapter,PersonTypeId,IsSaveAndNew,Pseudonym,ContactName")] MemberCreateViewModel viewModel)
        {
            ViewBag.User = await GetCurrentUser();

            if (_context.ApplicationUser.Any(a => a.Email == viewModel.Email))
            {
                ModelState.AddModelError("Email", "Email already in use");
            }

            var personTypes = await _context.PersonTypes.OrderBy(p => p.Name).ToListAsync();

            if (ModelState.IsValid)
            {
                var applicationUser = new ApplicationUser
                {
                    City         = viewModel.City,
                    Email        = viewModel.Email,
                    FirstName    = viewModel.FirstName,
                    LastName     = viewModel.LastName,
                    Pseudonym    = viewModel.Pseudonym,
                    ContactName  = viewModel.ContactName,
                    State        = viewModel.State,
                    Street1      = viewModel.Street1,
                    ZipCode      = viewModel.Zip,
                    PhoneNumber  = viewModel.Phone,
                    WhenJoined   = viewModel.WhenJoined,
                    WhenExpires  = viewModel.WhenExpires,
                    Status       = viewModel.Status,
                    UserName     = viewModel.Email,
                    PersonTypeId = viewModel.PersonTypeId
                };

                var result = await _userManager.CreateAsync(applicationUser, "1We%1We%" + DateTime.UtcNow.ToString());

                if (!string.IsNullOrEmpty(viewModel.Note))
                {
                    var note = new ApplicationUserNote
                    {
                        ApplicationUserId = applicationUser.Id,
                        AddedBy           = ViewBag.User,
                        WhenAdded         = DateTime.Now,
                        Note = viewModel.Note
                    };
                    _context.Add(note);
                }

                if (viewModel.Chapter != 0)
                {
                    _context.Add(new MemberChapter
                    {
                        ApplicationUserId = applicationUser.Id,
                        ChapterId         = viewModel.Chapter,
                        WhenJoined        = DateTime.Now
                    });
                }

                var personType = personTypes.FirstOrDefault(p => p.Id == viewModel.PersonTypeId);
                await _userManager.AddToRoleAsync(applicationUser, personType.Name);

                await _context.SaveChangesAsync();

                if (viewModel.IsSaveAndNew)
                {
                    return(RedirectToAction("Create"));
                }

                return(RedirectToAction("Index"));
            }
            var chapterSelect = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "0", Text = "None"
                }
            };
            var chapters = _context.Chapters.OrderBy(c => c.Name).ToList();

            foreach (var chapter in chapters)
            {
                chapterSelect.Add(new SelectListItem
                {
                    Value = chapter.Id.ToString(),
                    Text  = chapter.Name
                });
            }
            viewModel.Chapters     = chapterSelect;
            viewModel.IsSaveAndNew = false;

            var personTypesSelect = new List <SelectListItem>();

            foreach (var pt in personTypes)
            {
                personTypesSelect.Add(new SelectListItem
                {
                    Value = pt.Id.ToString(),
                    Text  = pt.Name
                });
            }
            viewModel.PersonTypes = personTypesSelect;

            return(View(viewModel));
        }