public static void AddAttendanceEvents(HomeGroupEventViewModel hgEvent, oikonomosEntities context, int eventValue, string eventName, Person currentPerson)
        {
            OldEvent groupEvent = new OldEvent();
            groupEvent.Created = DateTime.Now;
            groupEvent.CreatedByPersonId = currentPerson.PersonId;
            groupEvent.ChurchId = currentPerson.ChurchId;

            //Check to see if it is not already in the database
            var groupCheck = (from e in context.OldEvents
                              where e.TableId == (int)Tables.Group
                              && e.Reference == hgEvent.GroupId
                              && e.EventDate == hgEvent.EventDate
                              && e.Description == eventName
                              select e).FirstOrDefault();

            if (groupCheck != null)
            {
                groupEvent = groupCheck;
            }
            else
            {
                context.OldEvents.AddObject(groupEvent);
            }

            groupEvent.TableId = (int)Tables.Group;
            groupEvent.Reference = hgEvent.GroupId;
            groupEvent.Description = eventName;
            groupEvent.EventDate = hgEvent.EventDate;
            groupEvent.Value = eventValue.ToString();
            groupEvent.EventVisibilityId = (int)EventVisibilities.GroupAdministrators;
            groupEvent.Changed = DateTime.Now;
            groupEvent.ChangedByPersonId = currentPerson.PersonId;
        }
        public void Save(Person currentPerson, HomeGroupEventViewModel hgEvent)
        {
            if (hgEvent == null) return;
            var didAttend = 0;
            var didNotAttend = 0;
            foreach (var personEvents in hgEvent.Events)
            {
                var person = _personRepository.FetchPerson(personEvents.PersonId);
                foreach (var personEvent in personEvents.Events)
                {
                    var pe = EventDataAccessor.SavePersonEvent(Context, personEvents, currentPerson, personEvent);
                    EventDataAccessor.CheckToSeeIfEventAlreadyExists(personEvents, Context, personEvent, pe);

                    if (!person.HasPermission(Permissions.IncludeInGroupAttendanceStats)) continue;
                    if (personEvent.Name == EventNames.DidNotAttendGroup)
                        didNotAttend++;
                    if (personEvent.Name == EventNames.AttendedGroup)
                        didAttend++;
                }
            }

            //Add the attended and did not attend group events
            EventDataAccessor.AddAttendanceEvents(hgEvent, Context, didAttend, "Members attended", currentPerson);
            EventDataAccessor.AddAttendanceEvents(hgEvent, Context, didNotAttend, "Members did not attend", currentPerson);

            Context.SaveChanges();
        }
示例#3
0
        public JsonResult SaveHomeGroupEvent(HomeGroupEventViewModel hgEvent)
        {
            string message = string.Empty;
            bool sessionTimedOut = false;
            if (Session[SessionVariable.LoggedOnPerson] == null)
            {
                sessionTimedOut = true;
            }
            else
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];

                EventDataAccessor.SaveHomeGroupEvent(currentPerson, hgEvent);
            }

            var response = new
            {
                SessionTimeOut = sessionTimedOut,
                Message = message
            };
            return Json(response, JsonRequestBehavior.DenyGet);
        }
示例#4
0
        public static void SaveHomeGroupEvent(Person currentPerson, HomeGroupEventViewModel hgEvent)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var didAttend = 0;
                var didNotAttend = 0;
                foreach (var personEvents in hgEvent.Events)
                {
                    var person = PersonDataAccessor.FetchPerson(personEvents.PersonId);
                    foreach (var personEvent in personEvents.Events)
                    {
                        var pe = SavePersonEvent(context, personEvents, currentPerson, personEvent);
                        CheckToSeeIfEventAlreadyExists(personEvents, context, personEvent, pe);

                        if (!person.HasPermission(Permissions.IncludeInGroupAttendanceStats)) continue;
                        if(personEvent.Name == EventNames.DidNotAttendGroup)
                            didNotAttend++;
                        if(personEvent.Name == EventNames.AttendedGroup)
                            didAttend++;
                    }
                }

                //Add the attended and did not attend group events
                AddAttendanceEvents(hgEvent, context, didAttend, "Members attended", currentPerson);
                AddAttendanceEvents(hgEvent, context, didNotAttend, "Members did not attend", currentPerson);

                context.SaveChanges();
            }
        }