예제 #1
0
        public int CreateEvent(EventModel em)
        {
            int result = DaoUtilities.NO_CHANGES;

            EVENT ev = db.EVENT.Create();

            ev.EVENT_ID = em.EventId;
            ev.EVENT_NAME = em.name;
            ev.EVENT_DURATION = em.Duration;
            ev.EVENT_MAXNBR = em.MaxNb;
            ev.EVENT_PRICE = em.Price;
            ev.EVENT_ROOM = em.RoomId;
            ev.EVENT_ACTIVITY = em.ActivityId;
            ev.EVENT_CONTRIBUTOR = em.ContributorId;
            ev.EVENT_MANAGER = em.ManagerId;
            ev.EVENT_TYPE = em.Type;
            ev.EVENT_DATE = em.EventDate;

            db.EVENT.Add(ev);
            try
            {
                int saveResult = db.SaveChanges();

                if (saveResult == 1)
                    result = DaoUtilities.SAVE_SUCCESSFUL;
            }
            catch (DbUpdateConcurrencyException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.UPDATE_EXCEPTION;
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
            }
            catch (NotSupportedException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.UNSUPPORTED_EXCEPTION;
            }
            catch (ObjectDisposedException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.DISPOSED_EXCEPTION;
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.GetBaseException().ToString());
                result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
            }
            return result;
        }
예제 #2
0
        public int DeleteEvent(EventModel em)
        {
            int result = DaoUtilities.NO_CHANGES;

            EVENT ev = db.EVENT.Find(em.EventId);

            if (ev != null)
            {
                db.EVENT.Remove(ev);
                try
                {
                    int saveResult = db.SaveChanges();

                    if (saveResult == 1)
                        result = DaoUtilities.SAVE_SUCCESSFUL;
                }
                catch (DbUpdateConcurrencyException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_EXCEPTION;
                }
                catch (DbEntityValidationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
                }
                catch (NotSupportedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UNSUPPORTED_EXCEPTION;
                }
                catch (ObjectDisposedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.DISPOSED_EXCEPTION;
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
                }
            }

            return result;
        }
예제 #3
0
        public int DeleteRepetitiveEvents(EventModel em)
        {
            int result = DeleteEvent(em);

            if (result == DaoUtilities.SAVE_SUCCESSFUL)
            {
                IQueryable<REPETITIVE_EVENT> query = db.Set<REPETITIVE_EVENT>().Where(REPETITIVE_EVENT => REPETITIVE_EVENT.RE_ID == em.EventId);

                foreach (REPETITIVE_EVENT re in query)
                {
                    db.REPETITIVE_EVENT.Remove(re);
                }

                try
                {
                    int saveResult = db.SaveChanges();

                    if (saveResult != 0)
                        result = DaoUtilities.SAVE_SUCCESSFUL;
                }
                catch (DbUpdateConcurrencyException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_EXCEPTION;
                }
                catch (DbEntityValidationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
                }
                catch (NotSupportedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UNSUPPORTED_EXCEPTION;
                }
                catch (ObjectDisposedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.DISPOSED_EXCEPTION;
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
                }
            }
            return result;
        }
        /// <summary>
        /// Convert a event from the database to a EventModel
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public EventModel ConvertEventToEventModel(EVENT e)
        {
            EventModel em = new EventModel();

            if (e != null)
            {
                em.EventId = e.EVENT_ID;
                em.name = e.EVENT_NAME;
                em.Duration = e.EVENT_DURATION;
                em.MaxNb = e.EVENT_MAXNBR;
                em.Price = e.EVENT_PRICE;
                em.RoomId = e.EVENT_ROOM;
                em.ActivityId = e.EVENT_ACTIVITY;
                em.ContributorId = e.EVENT_CONTRIBUTOR;
                em.ManagerId = e.EVENT_MANAGER;
                em.Type = e.EVENT_TYPE;
                em.EventDate = e.EVENT_DATE;
            }
            else
                em = null;

            return em;
        }