Beispiel #1
0
        /// <summary>
        /// Retrieve on Applicant object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="personId"></param>
        /// <param name="id3"></param>
        /// <param name="id4"></param>
        /// <param name="id5"></param>
        /// <param name="id6"></param>
        /// <returns>presentation Applicant object or null if not found</returns>
        public override Applicant ReadOne(Guid id, Guid personId, Guid id3, int id4, int id5, int id6)
        {
            var obj = new Applicant();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Applicants
                          .Include(a => a.ApplicantOwnedAnimals)
                          .Include(a => a.ApplicantVeterinarian)
                          .Single(a => a.ID == id && a.PersonID == personId)
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
        /// <summary>
        /// Retrieve all EventAttendeees from the database for presentation
        /// </summary>
        /// <returns>list of EventAttendee</returns>
        public override List <EventAttendee> ReadAll()
        {
            var objList = new List <EventAttendee>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.Event_Attendee
                              .Include(p => p.Entity_Person)
                              .Include(p => p.Enum_EventAttendeeType)
                              .Include(p => p.Event_Registration)
                              .ToList()
                              .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
        /// <summary>
        /// Retrieve all Loges from the database for presentation
        /// </summary>
        /// <returns>list of Log</returns>
        public override List <OptionValue> ReadAll()
        {
            var objList = new List <OptionValue>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.Entity_StoreOptionValue
                              .Include(i => i.Entity_StoreOptionType)
                              .Include(i => i.Entity_StoreProductVariant)
                              .ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #4
0
        public EventSponsorshipLevelType ReadOne(int id)
        {
            var obj = new EventSponsorshipLevelType();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Event_SponsorshipLevelTypes
                          .Single(x => x.ID == id).ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
Beispiel #5
0
        /// <summary>
        /// Retrieve all Loges from the database for presentation
        /// </summary>
        /// <returns>list of Log</returns>
        public List <Event> ReadAll()
        {
            var objList = new List <Event>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.Events
                              .Include(p => p.Entity_Organisation)
                              .ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #6
0
        /// <summary>
        /// Retrieve on EventSponsor object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="id2">not used</param>
        /// <param name="id3">not used</param>
        /// <param name="id4">not used</param>
        /// <param name="id5">not used</param>
        /// <param name="id6">not used</param>
        /// <returns>presentation EventSponsor object or null if not found</returns>
        public override EventSponsor ReadOne(Guid id, Guid id2, Guid id3, int id4, int id5, int id6)
        {
            var obj = new EventSponsor();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Event_Sponsor
                          .Single(x => x.ID == id).ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
Beispiel #7
0
        /// <summary>
        /// Retrieve on Event object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="id2">not used</param>
        /// <param name="id3">not used</param>
        /// <param name="id4">not used</param>
        /// <param name="id5">not used</param>
        /// <param name="id6">not used</param>
        /// <returns>presentation Event object or null if not found</returns>
        public Event ReadOne(Guid id, Guid id2, Guid id3, int id4, int id5, int id6)
        {
            var obj = new Event();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Events
                          .Include(p => p.Entity_DonationItems)
                          .Include(p => p.Entity_Organisation)
                          .Include(p => p.Event_Registration)
                          .Include(p => p.Event_Sponsor)
                          .Single(item => item.ID.Equals(id))
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
        /// <summary>
        /// Retrieve all Loges from the database for presentation
        /// </summary>
        /// <returns>list of Log</returns>
        public override List <SystemConfig> ReadAll()
        {
            var objList = new List <SystemConfig>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.System_Config
                              .Include(i => i.System_ConfigCategory)
                              .ToList()
                              .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #9
0
        public CartItem ReadOne(int id, Guid cartId)
        {
            var obj = new CartItem();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Entity_StoreCartItem
                          .Find(id, cartId)
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
        /// <summary>
        /// Retrieve on OptionValue object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="id2">not used</param>
        /// <param name="id3">not used</param>
        /// <param name="id4">not used</param>
        /// <param name="id5">not used</param>
        /// <param name="id6">not used</param>
        /// <returns>presentation OptionValue object or null if not found</returns>
        public override OptionValue ReadOne(Guid id, Guid id2, Guid id3, int id4, int id5, int id6)
        {
            var obj = new OptionValue();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Entity_StoreOptionValue
                          .Include(i => i.Entity_StoreOptionType)
                          .Include(i => i.Entity_StoreProductVariant)
                          .Single(item => item.Id.Equals(id))
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
        /// <summary>
        /// Retrieve list of presentation objects filtered by provided object's properties
        /// </summary>
        /// <param name="obj">Presentation object with properties used to filter database query</param>
        /// <returns>List of DonationItems objects filtered and then sorted by name</returns>
        public override List <DonationItems> ReadFiltered(DonationItems obj)
        {
            var objList = new List <DonationItems>();

            try
            {
                // Build dynamic query based on the provided presentation object's properties
                // http://stackoverflow.com/questions/13628748/linq-dynamic-query-for-entity-framework
                var conditions = new List <Func <Entity_DonationItems, bool> >();
                if (Guid.Empty != obj.Id)
                {
                    conditions.Add(x => x.ID == obj.Id);
                }

                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    var query = context.Entity_DonationItems.AsQueryable();
                    query = conditions.Aggregate(query, (current, condition) => current.Where(condition).AsQueryable());

                    // convert to presentation object
                    objList = query.OrderByDescending(a => a.DateReceived).ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
        /// <summary>
        /// Retrieve all Loges from the database for presentation
        /// </summary>
        /// <returns>list of Log</returns>
        public override List <ShippingMethod> ReadAll()
        {
            var objList = new List <ShippingMethod>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.Entity_StoreShippingMethod
                              .ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
        /// <summary>
        /// Retrieve on ShippingMethod object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="id2">not used</param>
        /// <param name="id3">not used</param>
        /// <param name="id4">not used</param>
        /// <param name="id5">not used</param>
        /// <param name="id6">not used</param>
        /// <returns>presentation ShippingMethod object or null if not found</returns>
        public override ShippingMethod ReadOne(Guid id, Guid id2, Guid id3, int id4, int id5, int id6)
        {
            var obj = new ShippingMethod();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Entity_StoreShippingMethod
                          .Single(item => item.Id.Equals(id))
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
Beispiel #14
0
        /// <summary>
        /// Retrieve all Loges from the database for presentation
        /// </summary>
        /// <returns>list of Log</returns>
        public override List <Order> ReadAll()
        {
            var objList = new List <Order>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.Entity_StoreOrder
                              .Include(i => i.Entity_StoreOrderDetail)
                              .Include(i => i.Entity_Addresses)
                              .Include(i => i.Entity_Addresses1)
                              .Include(i => i.Entity_Base)
                              .Include(i => i.Entity_StorePayment)
                              .Include(i => i.Entity_StoreShipment)
                              .ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="settingName"></param>
        /// <returns></returns>
        public SystemConfigCategory ReadOne(string categoryId)
        {
            var obj = new SystemConfigCategory();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.System_ConfigCategory
                          .Single(i => i.Name.Equals(categoryId))
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
Beispiel #16
0
        /// <summary>
        /// Retrieve all Businesses from the database for presentation
        /// </summary>
        /// <returns>list of Business</returns>
        public override List <Business> ReadAll()
        {
            var objList = new List <Business>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    objList = context.Entity_Organisation
                              .Include(p => p.Entity_Base)
                              .Include(p => p.Entity_Base.Entity_Addresses)
                              .Include(p => p.Entity_Base.Entity_EmailAddress)
                              .Include(p => p.Entity_Base.Entity_PhoneNumber)
                              .ToList()
                              .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #17
0
        public OrderDetail ReadOne(int id, Guid orderId)
        {
            var obj = new OrderDetail();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Entity_StoreOrderDetail
                          .Include(i => i.Entity_StoreProductVariant)
                          .Single(i => i.Id == id && i.OrderId == orderId)
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
Beispiel #18
0
        /// <summary>
        /// Retrieve on Order object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="id2">not used</param>
        /// <param name="id3">not used</param>
        /// <param name="id4">not used</param>
        /// <param name="id5">not used</param>
        /// <param name="id6">not used</param>
        /// <returns>presentation Order object or null if not found</returns>
        public override Order ReadOne(Guid id, Guid id2, Guid id3, int id4, int id5, int id6)
        {
            var obj = new Order();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Entity_StoreOrder
                          .Include(i => i.Entity_StoreOrderDetail)
                          .Include(i => i.Entity_Addresses)
                          .Include(i => i.Entity_Addresses1)
                          .Include(i => i.Entity_Base)
                          .Include(i => i.Entity_StorePayment)
                          .Include(i => i.Entity_StoreShipment)
                          .Single(item => item.Id.Equals(id))
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
        /// <summary>
        /// Retrieve on EventAttendee object for presentation
        /// </summary>
        /// <param name="id">id to look up the Applicant in the database</param>
        /// <param name="id2">not used</param>
        /// <param name="id3">not used</param>
        /// <param name="id4">not used</param>
        /// <param name="id5">not used</param>
        /// <param name="id6">not used</param>
        /// <returns>presentation EventAttendee object or null if not found</returns>
        public override EventAttendee ReadOne(Guid id, Guid id2, Guid id3, int id4, int id5, int id6)
        {
            var obj = new EventAttendee();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Event_Attendee
                          .Include(p => p.Entity_Person)
                          .Include(p => p.Enum_EventAttendeeType)
                          .Include(p => p.Event_Registration)
                          .Single(x => x.ID == id)
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
        /// <summary>
        /// Updated existing EventRegistration in the database
        /// </summary>
        /// <param name="obj">EventRegistration object to be Updated in the database</param>
        /// <returns>success or failure</returns>
        public ServiceResultEnum Update(ref RoughRiderRegistration obj)
        {
            // Number of changes as a result of the database change
            NumberChanges = 0;
            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to database object
                    var dbObj = obj.EventRegistration.ToModel();

                    // add to the database and retrieve the updated object back (namely the GUID generated into the Id)
                    context.Entry(dbObj).State = EntityState.Modified;

                    // commit changes to the database
                    NumberChanges = context.SaveChanges();

                    // convert the database object back to a presentation object with included changes from the database (if any)
                    obj.EventRegistration = dbObj.ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
                Messages.Add(ex.Message);
            }
            catch (DbEntityValidationException ex)
            {
                Messages.AddRange(Common.FormatEntityValidationError(ex));
            }

            return(NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure);
        }
Beispiel #21
0
        /// <summary>
        /// Retrieve on Business object for presentation
        /// </summary>
        /// <param name="id">id to look up the Business in the database</param>
        /// <param name="personId"></param>
        /// <param name="id3"></param>
        /// <param name="id4"></param>
        /// <param name="id5"></param>
        /// <param name="id6"></param>
        /// <returns>presentation Business object or null if not found</returns>
        public override Business ReadOne(Guid id, Guid personId, Guid id3, int id4, int id5, int id6)
        {
            var obj = new Business();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    obj = context.Entity_Organisation
                          .Include(p => p.Entity_Base)
                          .Include(p => p.Entity_Base.Entity_Addresses)
                          .Include(p => p.Entity_Base.Entity_EmailAddress)
                          .Include(p => p.Entity_Base.Entity_PhoneNumber)
                          .Single(p => p.ID == id)
                          .ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(obj);
        }
Beispiel #22
0
        /// <summary>
        /// Retrieve list of presentation objects filtered by provided object's properties
        /// </summary>
        /// <param name="obj">Presentation object with properties used to filter database query</param>
        /// <returns>List of File objects filtered and then sorted by name</returns>
        public override List <File> ReadFiltered(File obj)
        {
            var objList = new List <File>();

            try
            {
                // Build dynamic query based on the provided presentation object's properties
                // http://stackoverflow.com/questions/13628748/linq-dynamic-query-for-entity-framework
                var conditions = new List <Func <Entity_File, bool> >();
                if (!string.IsNullOrEmpty(obj.ContentType))
                {
                    conditions.Add(x => x.ContentType.Equals(obj.ContentType));
                }
                if (!string.IsNullOrEmpty(obj.ServerPath))
                {
                    conditions.Add(x => x.ServerPath.Contains(obj.ServerPath));
                }
                if (Guid.Empty != obj.ID)
                {
                    conditions.Add(x => x.ID == obj.ID);
                }
                if (Guid.Empty != obj.BusinessID)
                {
                    conditions.Add(x => x.OrgID == obj.BusinessID);
                }
                if (Guid.Empty != obj.DogID)
                {
                    conditions.Add(x => x.DogID == obj.DogID);
                }
                if (Guid.Empty != obj.PersonID)
                {
                    conditions.Add(x => x.PersonID == obj.PersonID);
                }
                if (obj.DateCreated != DateTime.MinValue)
                {
                    conditions.Add(x => x.DateCreated >= obj.DateCreated);
                }

                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    var query = context.Entity_File.AsQueryable();
                    query = conditions.Aggregate(query, (current, condition) => current.Where(condition).AsQueryable());

                    // convert to presentation object
                    objList = query.OrderByDescending(a => a.ServerPath).ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #23
0
        /// <summary>
        /// Retrieve list of presentation objects filtered by provided object's properties
        /// </summary>
        /// <param name="obj">Presentation object with properties used to filter database query</param>
        /// <returns>List of EventSponsor objects filtered and then sorted by name</returns>
        public override List <EventSponsor> ReadFiltered(EventSponsor obj)
        {
            var objList = new List <EventSponsor>();

            try
            {
                // Build dynamic query based on the provided presentation object's properties
                // http://stackoverflow.com/questions/13628748/linq-dynamic-query-for-entity-framework
                var conditions = new List <Func <Event_Sponsor, bool> >();
                if (!string.IsNullOrEmpty(obj.Comments))
                {
                    conditions.Add(x => x.Comments.Contains(obj.Comments));
                }
                if (obj.DonationAmount >= 0)
                {
                    conditions.Add(x => x.DonationAmount >= obj.DonationAmount);
                }
                conditions.Add(x => x.IsDonating == obj.IsDonating);
                conditions.Add(x => x.IsDonationRecieved == obj.IsDonationReceived);
                conditions.Add(x => x.IsSingageComplete == obj.IsSingageComplete);
                conditions.Add(x => x.IsSponsoring == obj.IsSponsoring);
                if (Guid.Empty != obj.Id)
                {
                    conditions.Add(x => x.ID == obj.Id);
                }
                if (Guid.Empty != obj.EventId)
                {
                    conditions.Add(x => x.EventID == obj.EventId);
                }
                if (Guid.Empty != obj.PersonId)
                {
                    conditions.Add(x => x.PersonID == obj.PersonId);
                }
                if (Guid.Empty != obj.BusinessId)
                {
                    conditions.Add(x => x.OrganisationID == obj.BusinessId);
                }

                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    var query = context.Event_Sponsor.AsQueryable();
                    query = conditions.Aggregate(query, (current, condition) => current.Where(condition).AsQueryable());

                    // convert to presentation object
                    objList = query.OrderByDescending(a => a.DateAdded).ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #24
0
        /// <summary>
        /// Retrieve list of presentation objects filtered by provided object's properties
        /// </summary>
        /// <param name="obj">Presentation object with properties used to filter database query</param>
        /// <returns>List of Applicant objects filtered and then sorted by name</returns>
        public override List <Applicant> ReadFiltered(Applicant obj)
        {
            var objList = new List <Applicant>();

            try
            {
                // Build dynamic query based on the provided presentation object's properties
                // http://stackoverflow.com/questions/13628748/linq-dynamic-query-for-entity-framework
                var conditions = new List <Func <Model.Applicant, bool> >();
                if (obj.ID != Guid.Empty)
                {
                    conditions.Add(e => e.ID == obj.ID);
                }
                if (!string.IsNullOrEmpty(obj.ApplicantType))
                {
                    conditions.Add(e => e.ApplicantType.Equals(obj.ApplicantType));
                }
                if (!string.IsNullOrEmpty(obj.AppNameLast))
                {
                    conditions.Add(e => e.AppNameLast.Contains(obj.AppNameLast));
                }
                if (!string.IsNullOrEmpty(obj.AppNameFirst))
                {
                    conditions.Add(e => e.AppNameLast.Contains(obj.AppNameFirst));
                }
                if (obj.DateSubmitted != null)
                {
                    conditions.Add(e => e.DateSubmitted.Equals(obj.DateSubmitted));
                }
                if (obj.DateSubmittedMax != null)
                {
                    conditions.Add(e => e.DateSubmitted <= obj.DateSubmittedMax);
                }
                if (obj.DateSubmittedMin != null)
                {
                    conditions.Add(e => e.DateSubmitted >= obj.DateSubmittedMin);
                }

                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    var query = context.Applicants.AsQueryable();
                    query = conditions.Aggregate(query, (current, condition) => current.Where(condition).AsQueryable());

                    // convert to presentation object
                    objList = query.OrderByDescending(a => a.DateSubmitted).ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
Beispiel #25
0
        /// <summary>
        /// Retrieve list of presentation objects filtered by provided object's properties
        /// </summary>
        /// <param name="obj">Presentation object with properties used to filter database query</param>
        /// <returns>List of Address objects filtered and then sorted by name</returns>
        public override List <Address> ReadFiltered(Address obj)
        {
            var objList = new List <Address>();

            try
            {
                // Build dynamic query based on the provided presentation object's properties
                // http://stackoverflow.com/questions/13628748/linq-dynamic-query-for-entity-framework
                var conditions = new List <Func <Model.Entity_Addresses, bool> >();
                if (!string.IsNullOrEmpty(obj.City))
                {
                    conditions.Add(x => x.City.Contains(obj.City));
                }
                if (!string.IsNullOrEmpty(obj.StateID))
                {
                    conditions.Add(x => x.StateID.Contains(obj.StateID));
                }
                if (!string.IsNullOrEmpty(obj.Street))
                {
                    conditions.Add(x => x.Street.Contains(obj.Street));
                }
                if (!string.IsNullOrEmpty(obj.Street2))
                {
                    conditions.Add(x => x.Street2.Contains(obj.Street2));
                }
                if (!string.IsNullOrEmpty(obj.Type))
                {
                    conditions.Add(x => x.Type.Contains(obj.Type));
                }
                if (!string.IsNullOrEmpty(obj.ZIP))
                {
                    conditions.Add(x => x.ZIP.Contains(obj.ZIP));
                }
                if (Guid.Empty != obj.EntityID)
                {
                    conditions.Add(x => x.EntityID == obj.EntityID);
                }

                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    var query = context.Entity_Addresses.AsQueryable();
                    query = conditions.Aggregate(query, (current, condition) => current.Where(condition).AsQueryable());

                    // convert to presentation object
                    objList = query.OrderByDescending(a => a.Street).ToList().ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }
        /// <summary>
        /// Delete an EventRegistration from the database
        /// </summary>
        /// <param name="id">EventRegistration id the object to be deleted from the database</param>
        /// <returns>success or failure</returns>
        public override ServiceResultEnum Delete(Guid id)
        {
            // Number of changes as a result of the database change
            NumberChanges = 0;
            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to database object
                    var dbObj = context.Event_Registration.Find(id);
                    dbObj.Event = null;
                    if (dbObj != null)
                    {
                        // delete event attendees and associated objects
                        var isAnyErrorDeletingAttendees = false;
                        var eventAttendeeHandler        = new EventAttendeeHandler();
                        foreach (var attendee in dbObj.Event_Attendee)
                        {
                            var resultAttendeeDelete = eventAttendeeHandler.Delete(attendee.ID);
                            if (resultAttendeeDelete == ServiceResultEnum.Failure)
                            {
                                isAnyErrorDeletingAttendees = true;
                                Messages.AddRange(eventAttendeeHandler.Messages);
                                Messages.Add("Error while deleting attendee with ID: " + attendee.ID);
                                break;
                            }
                        }

                        if (!isAnyErrorDeletingAttendees)
                        {
                            context.Event_Registration.Remove(dbObj);
                            // commit changes to the database
                            NumberChanges = context.SaveChanges();
                        }
                        else
                        {
                            ServiceResult = ServiceResultEnum.Failure;
                            Messages.Add("Event Registration not deleted. ID: " + dbObj.ID);
                        }
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (ValidationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure);
        }
Beispiel #27
0
        /// <summary>
        /// Add new EventSponsor to the database
        /// </summary>
        /// <param name="obj">EventSponsor object to be saved to the database</param>
        /// <returns>success or failure</returns>
        public override ServiceResultEnum Create(ref EventSponsor obj)
        {
            // Number of changes as a result of the database change
            NumberChanges = 0;
            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to database object
                    var dbObj = obj.ToModel();

                    if (dbObj.SponsorshipLevel != 0)
                    {
                        if (dbObj.SponsorshipLevel != null)
                        {
                            dbObj.Event_SponsorshipLevel.Add(new Event_SponsorshipLevel {
                                SponsorshipLevelType = (int)dbObj.SponsorshipLevel
                            });
                        }
                    }

                    if (dbObj.OrganisationID.Equals(Guid.Empty))
                    {
                        dbObj.OrganisationID = null;
                    }
                    if (dbObj.PersonID.Equals(Guid.Empty))
                    {
                        dbObj.PersonID = null;
                    }

                    // add to the database and retrieve the updated object back (namely the GUID generated into the Id)
                    dbObj = context.Event_Sponsor.Add(dbObj);

                    // commit changes to the database
                    NumberChanges = context.SaveChanges();

                    // convert the database object back to a presentation object with included changes from the database (if any)
                    obj = dbObj.ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (ValidationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure);
        }
Beispiel #28
0
        /// <summary>
        /// Updated existing Base in the database
        /// </summary>
        /// <param name="obj">Base object to be Updated in the database</param>
        /// <returns>success or failure</returns>
        public override ServiceResultEnum Update(ref Base obj)
        {
            // Number of changes as a result of the database change
            NumberChanges = 0;
            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to database object
                    var dbObj = obj.ToModel();

                    // add to the database and retrieve the updated object back (namely the GUID generated into the Id)
                    context.Entry(dbObj).State = EntityState.Modified;

                    for (var index = 0; index < obj.Addresses.Count; index++)
                    {
                        var address        = obj.Addresses[index];
                        var addressHandler = new AddressHandler();
                        addressHandler.Update(ref address);
                    }
                    for (var index = 0; index < obj.EmailAddresses.Count; index++)
                    {
                        var address        = obj.EmailAddresses[index];
                        var addressHandler = new EmailAddressHandler();
                        addressHandler.Update(ref address);
                    }
                    for (var index = 0; index < obj.PhoneNumbers.Count; index++)
                    {
                        var phone        = obj.PhoneNumbers[index];
                        var phoneHandler = new PhoneNumberHandler();
                        phoneHandler.Update(ref phone);
                    }

                    // commit changes to the database
                    NumberChanges = context.SaveChanges();

                    // convert the database object back to a presentation object with included changes from the database (if any)
                    obj = dbObj.ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (ValidationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure);
        }
Beispiel #29
0
        /// <summary>
        /// Updated existing EventSponsor in the database
        /// </summary>
        /// <param name="obj">EventSponsor object to be Updated in the database</param>
        /// <returns>success or failure</returns>
        public override ServiceResultEnum Update(ref EventSponsor obj)
        {
            // Number of changes as a result of the database change
            NumberChanges = 0;
            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to database object
                    var dbObj = obj.ToModel();

                    var sponsorToDetach = context.Event_Sponsor.Single(s => s.ID.Equals(dbObj.ID));
                    if (sponsorToDetach == null)
                    {
                        return(ServiceResultEnum.Failure);
                    }

                    if (dbObj.OrganisationID.Equals(Guid.Empty))
                    {
                        dbObj.OrganisationID = null;
                    }
                    if (dbObj.PersonID.Equals(Guid.Empty))
                    {
                        dbObj.PersonID = null;
                    }

                    // add to the database and retrieve the updated object back (namely the GUID generated into the Id)
                    context.Entry(dbObj).State = EntityState.Modified;

                    // commit changes to the database
                    NumberChanges = context.SaveChanges();

                    // convert the database object back to a presentation object with included changes from the database (if any)
                    obj = dbObj.ToViewModel();
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (ValidationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure);
        }
        /// <summary>
        /// Retrieve all EventRegistrationes from the database for presentation
        /// </summary>
        /// <returns>list of EventRegistration</returns>
        public List <RoughRiderRegistration> ReadAll()
        {
            var objList = new List <RoughRiderRegistration>();

            try
            {
                // Perform data access using the context
                using (var context = new HuskyRescueEntities())
                {
                    // convert to presentation object
                    var objEventRegList = context.Event_Registration
                                          .Include(p => p.Event)
                                          .Include(p => p.Event_Attendee)
                                          .ToList()
                                          .ToViewModel();
                    var miscHandler     = new Enum.MiscHandler();
                    var miscGolfEvent   = miscHandler.ReadOne("golfevent");
                    var miscRaffleEvent = miscHandler.ReadOne("roughriderevent");
                    var miscRoughRiders = miscHandler.ReadOne("raffle");

                    foreach (var item in objEventRegList)
                    {
                        if (item.Event.Id.ToString().ToLower() == miscGolfEvent.Value.ToLower())
                        {
                            item.Event.IsActiveGolfEvent = true;
                        }
                        if (item.Event.Id.ToString().ToLower() == miscRoughRiders.Value.ToLower())
                        {
                            item.Event.IsActiveRoughRidersEvent = true;
                        }
                        if (item.Event.Id.ToString().ToLower() == miscRaffleEvent.Value.ToLower())
                        {
                            item.Event.IsActiveRaffle = true;
                        }
                        objList.Add(new RoughRiderRegistration {
                            EventRegistration = item
                        });
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return(objList);
        }