Beispiel #1
0
        public async Task <KeyValuePair <bool, string> > Add(Member member)
        {
            await _memberContext.Member.AddAsync(member);

            await _memberContext.SaveChangesAsync();

            var username = member.FirstName.Substring(0, 4) + member.LastName.Substring(0, 4) + "123";
            var password = "******";

            if (member.IsGroupAdmin)
            {
                var user = new IdentityUser()
                {
                    PhoneNumber = member.PhoneNumber,
                    UserName    = username
                };

                var result = await _userManager.CreateAsync(user, password);

                if (!result.Succeeded)
                {
                    return(new KeyValuePair <bool, string>(false, string.Join(".", result.Errors.Select(x => x.Description))));
                }

                result = await _userManager.AddToRoleAsync(user, "GroupAdmin");

                if (!result.Succeeded)
                {
                    await _userManager.DeleteAsync(user);

                    return(new KeyValuePair <bool, string>(false, string.Join(".", result.Errors.Select(x => x.Description))));
                }
            }
            return(new KeyValuePair <bool, string>(true, "Added Successfully"));
        }
        public async Task <KeyValuePair <bool, string> > Add(Group group)
        {
            await _membersDb.Group.AddAsync(group);

            await _membersDb.SaveChangesAsync();

            return(new KeyValuePair <bool, string>(true, "Added Successfully"));
        }
        public async Task <ActionResult> Create([Bind(Include = "MemberImageId,FileName,Title")] MemberImage memberImage)
        {
            if (ModelState.IsValid)
            {
                db.MemberImages.Add(memberImage);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Members"));
            }

            ViewBag.MemberImageId = new SelectList(db.Members, "MemberId", "Name", memberImage.MemberImageId);
            return(View(memberImage));
        }
Beispiel #4
0
        public async Task <KeyValuePair <bool, string> > MarkAttendace(int memberId)
        {
            try
            {
                var eventId = _eventRepository.GetActiveEvent().EventId;

                var count = MemberEventAttendanceCount(memberId);
                if (count > 0)
                {
                    await UpdateMemberEventCount(eventId, memberId);
                }
                else
                {
                    var Attendance = new Attendance
                    {
                        EventId  = eventId,
                        MemberId = memberId
                    };
                    await _membersDbContext.Attendance.AddAsync(Attendance);

                    await _membersDbContext.SaveChangesAsync();
                }

                string response = (count == 0) ? "mark" : "unmark";
                return(new KeyValuePair <bool, string>(true, response));
            }
            catch (Exception ex)
            {
                return(new KeyValuePair <bool, string>(false, ex.Message));
            }
        }
        public async Task RunAtTimeOf(DateTime now)
        {
            //do work here
            DayOfWeek Today  = DateTime.Today.DayOfWeek;
            var       events = _memberDb.Event.ToList();

            events.ForEach(x => x.IsActive = false);
            _memberDb.SaveChanges();
            if (Today == DayOfWeek.Sunday)
            {
                var sundayEvent = _memberDb.Event.Where(x => x.Name.ToLower() == "sunday service").FirstOrDefault();
                sundayEvent.IsActive = true;
                await _memberDb.SaveChangesAsync();
            }
            else if (Today == DayOfWeek.Wednesday)
            {
                var wednesdayEvent = _memberDb.Event.Where(x => x.Name.ToLower() == "bible study").FirstOrDefault();
                wednesdayEvent.IsActive = true;
                await _memberDb.SaveChangesAsync();
            }
            await _memberDb.SaveChangesAsync();
        }