public void update_prerequisite()
        {
            var handler = CreateHandler();

            //setup
            var request = new UpdateEventPrerequisiteRequest
            {
                Id = 1,
                EventId = 1,
                AssociatedEventId = 2,
                Description = "This event is optional."
            };

            var response = HandleRequest<UpdateEventPrerequisiteResponse>(handler, request);

            //assert
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var eventPrerequisite = context.CreateObjectSet<EventPrerequisite>().SingleOrDefault(p => p.Id == request.Id);

                Assert.AreEqual(request.Id, eventPrerequisite.Id);
                Assert.AreEqual(request.EventId, eventPrerequisite.EventId);
                Assert.AreEqual(request.AssociatedEventId, eventPrerequisite.AssociatedEventId);
                Assert.AreEqual(request.Description, eventPrerequisite.Description);
            }
        }
        public void update_prerequisite_with_invalid_id()
        {
            var handler = CreateHandler();

            //setup
            var request = new UpdateEventPrerequisiteRequest
            {
                Id = 0,
                EventId = 1,
                AssociatedEventId = 2,
                Description = "This event is optional."
            };

            var response = HandleRequest<UpdateEventPrerequisiteResponse>(handler, request);
        }
        public static void Save(EventAdminDetailView parent, SubEntity eventPrereqs, int eventId)
        {
            try
            {
                eventPrereqs.ErrorMessage = string.Empty;

                //Edits
                foreach (var record in eventPrereqs.Records.Where(r => r.Action == RecordActions.Edited))
                {
                    CheckRequiredFields(record);

                    var request = new UpdateEventPrerequisiteRequest
                    {
                        Id = int.Parse(parent.GetFieldValue(record.Fields, _id)),
                        EventId = eventId,
                        AssociatedEventId = int.Parse(parent.GetFieldValue(record.Fields, _associatedEventId)),
                        Description = parent.GetFieldValue(record.Fields, _prerequisiteDescription),
                        DisplayOrder = int.Parse(parent.GetFieldValue(record.Fields, _prerequisiteOrder))
                    };

                    parent.ProcessRequest<UpdateEventPrerequisiteResponse>(request);
                }

                //Existing Records Added
                foreach (var record in eventPrereqs.Records.Where(r => r.Action == RecordActions.Added))
                {
                    CheckRequiredFields(record);

                    var request = new AddEventPrerequisiteRequest
                        {
                            EventId = eventId,
                            AssociatedEventId = int.Parse(parent.GetFieldValue(record.Fields, _associatedEventId)),
                            Description = parent.GetFieldValue(record.Fields, _prerequisiteDescription),
                            DisplayOrder = int.Parse(parent.GetFieldValue(record.Fields, _prerequisiteOrder))
                        };
                    parent.ProcessRequest<AddEventPrerequisiteResponse>(request);
                }

                //Records Deleted
                foreach (var record in eventPrereqs.Records.Where(r => r.Action == RecordActions.Deleted))
                {
                    var request = new DeleteEventPrerequisiteRequest()
                    {
                        Id = int.Parse(parent.GetFieldValue(record.Fields, _id)),
                    };
                    parent.ProcessRequest<DeleteEventPrerequisiteResponse>(request);
                }
            }
            catch (Exception ex)
            {
                eventPrereqs.ErrorMessage = ex.Message;
                throw;
            }

            eventPrereqs = BuildSubEntity(parent, eventId);
        }