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

            //setup
            var request = new AddEventPrerequisiteRequest
            {
                EventId = 2,
                AssociatedEventId = 1,
                Description = "This is a mandatory prerequisite."
            };

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

            handler = CreateHandler();
            HandleRequest<AddEventPrerequisiteResponse>(handler, request);
        }
        public void add_prerequisite()
        {
            var handler = CreateHandler();

            //setup
            var request = new AddEventPrerequisiteRequest
            {
                EventId = 2,
                AssociatedEventId = 1,
                Description = "This is a mandatory prerequisite."
            };

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

            //assert
            using (var context = _objectContextFactory.CreateObjectContext())
            {
                var eventPrerequisite = context.CreateObjectSet<EventPrerequisite>().SingleOrDefault(p => p.Id == response.Id);
                Assert.AreEqual(request.EventId, eventPrerequisite.EventId);
                Assert.AreEqual(request.AssociatedEventId, eventPrerequisite.AssociatedEventId);
                Assert.AreEqual(request.Description, eventPrerequisite.Description);
            }
        }
        public void delete_prerequisite()
        {
            // add a request
            var addHandler = CreateAddHandler();

            var addRequest = new AddEventPrerequisiteRequest
            {
                EventId = 2,
                AssociatedEventId = 1,
                Description = "This is a mandatory prerequisite."
            };

            var addResponse = HandleRequest<AddEventPrerequisiteResponse>(addHandler, addRequest);

            // delete the newly added request
            var deleteHandler = CreateDeleteHandler();

            var deleteRequest = new DeleteEventPrerequisiteRequest
            {
                Id = addResponse.Id
            };

            var deleteResponse = HandleRequest<DeleteEventPrerequisiteResponse>(deleteHandler, deleteRequest);
        }
        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);
        }