Exemplo n.º 1
0
        public void AddNotice(string circleKey, int memberId, Guid eventId, string text)
        {
            var db   = _uow.DbContext;
            var data = new ActivitysNotices()
            {
                ToRoomId      = circleKey,
                MemberId      = memberId,
                EventId       = eventId,
                NoticeContent = text,
                HasClick      = false,
                CreateTime    = DateTime.UtcNow
            };

            db.ActivitysNotice.Add(data);


            //       return GetNoticeList(circleKey,memberId, 1);
        }
Exemplo n.º 2
0
        public bool AddMutipleNotice(string circleKey, List <int> memberIds, Guid eventId, string text)
        {
            var noticeRep = _uow.EntityRepository <ActivitysNotices>();

            foreach (var memberId in memberIds)
            {
                var data = new ActivitysNotices()
                {
                    ToRoomId      = circleKey,
                    MemberId      = memberId,
                    EventId       = eventId,
                    NoticeContent = text,
                    HasClick      = false,
                    CreateTime    = DateTime.UtcNow
                };
                noticeRep.Insert(data);
            }
            // 2018-04-02 yuschang 這裡透過捕獲異常的方式將例外重新封裝並向上拋出
            try
            {
                _uow.SaveChanges();

                return(true);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                return(false);

                throw raise;
            }
        }