public AuditFuneralNotice(FuneralNotice notice, AuditState newState) : this()
        {
            if (notice.Id == 0)
            {
                if(newState != AuditState.Creating && newState != AuditState.EmptyIdPermavita)
                {
                    throw new Exception("Sanity check. Notice ID=0, but state is: " + newState);
                }
            }

            this.FuneraNoticeId = notice.Id;
            this.MemorialId = notice.MemorialId;
            this.CedarCode = notice.CedarCode;
            this.BranchId = notice.BranchId;
            this.CreateDate = notice.CreateDate;
            this.ModifiedDate = notice.ModifiedDate;
            this.KnownAs = notice.KnownAs;
            this.OnlineMemorialUrl = notice.OnlineMemorialUrl;
            this.DeceasedImageUrl = notice.DeceasedImageUrl;
            this.ParentBranchId = notice.ParentBranchId;
            this.Surname = notice.Surname;
            this.FirstNames = notice.FirstNames;
            this.DateOfDeath = notice.DateOfDeath;
            this.DateOfFuneral = notice.DateOfFuneral;
            this.Obituary = notice.Obituary;
            this.Source = notice.Source;
            this.ShowDeceasedImage = notice.ShowDeceasedImage;
            this.RemoveNotice = notice.RemoveNotice;

            AuditState = newState;
        }
示例#2
0
        public EpiFindNotice(FuneralNotice notice) : this()
        {
            Id = notice.Id;
            IsOnlineMemorial = notice.IsOnlineMemorial();
            //json ignore
            //MemorialId = notice.MemorialId;
            //BranchId = notice.BranchId;
            //KnownAs = notice.KnownAs;
            CedarCode = notice.CedarCode;
            OnlineMemorialUrl = notice.OnlineMemorialUrl;
            DeceasedImageUrl = notice.DeceasedImageUrl;
            ParentBranchId = notice.ParentBranchId;
            Surname = notice.Surname;
            FirstNames = notice.FirstNames;
            DateOfDeath = notice.DateOfDeath;
            DateOfFuneral = notice.DateOfFuneral;
            Obituary = notice.Obituary;
            
            ShowDeceasedImage = notice.ShowDeceasedImage;
            RemoveNotice = notice.RemoveNotice;
            this.Source = notice.Source;
            this.NoticeState = notice.NoticeState;
            
            DayOfDeath = DateOfDeath.Day;
            MonthOfDeath = DateOfDeath.Month;
            YearOfDeath = DateOfDeath.Year;

            if (!IsOnlineMemorial)
            {
                TimeToLive = LoggerConfiguration.Inst.NoticesTimeToLeave;
            }
        }
示例#3
0
 private FuneralNotice CreateEmptyNotice()
 {
     var notice = new FuneralNotice();
     notice.Id = -1;
     notice.DateOfDeath = DateTime.UtcNow;
     notice.DateOfFuneral = DateTime.UtcNow;
     return notice;
 }
示例#4
0
        public void Log(FuneralNotice notice, Exception exception)
        {
            var state = GetFromExceptionType(exception);
            string errorMessage = exception.Message;
            Log(notice, state, errorMessage);

            if (CanLogToElmah(state))
            {
                exception.LogToElmah();
            }
        }
 private void AddNotice(FuneralNotice notice)
 {
     try
     {
         logger.Log(notice, AuditState.Validated);
         //
         ctx.FuneralNotices.Add(notice);
         ctx.SaveChanges();
         //
         logger.Log(notice, AuditState.SavedToDb);
     }
     catch (Exception ex)
     {
         logger.Log(notice, ex); //should store in Elmah
     }
 }
        public FuneralNotice Build()
        {
            var notice = new FuneralNotice(Id, FirstNames, Surname)
            {
                MemorialId = MemorialId,
                ParentBranchId = ParentBranchId,
                Source = Source,
                Obituary = Obituary,
                KnownAs = KnownAs,
                OnlineMemorialUrl = OnlineMemorialUrl,
                DeceasedImageUrl = DeceasedImageUrl,
                DateOfDeath = DateOfDeath,
                DateOfFuneral = DateOfFuneral,
                ModifiedDate = ModifiedDate
            };

            return notice;
        }
        public override void Up()
        {
            var notice = new FuneralNotice(1, "test", "test")
            {
                MemorialId = 1,
                ParentBranchId = "1",
                CedarCode = "cedarCode",
                BranchId = "1",
                KnownAs = "knownAs",
                Obituary = "Obituary",
                Source = SourceType.PERMAVITA,
                DateOfDeath = DateTime.UtcNow,
                DateOfFuneral = DateTime.UtcNow,
            };

            using (var context = new NoticesContext())
            {
                context.FuneralNotices.Add(notice);
            }
        }
示例#8
0
        public void Log(FuneralNotice notice, AuditState newState, string error = null)
        {
            notice = notice ?? CreateEmptyNotice(); 
            var audit = new AuditFuneralNotice(notice, newState) {Error = error};

            if (CanLogToDB(newState))
            {
                AddAuditNotice(audit);
            }

            if (error == null) //there is no exception
            {
                if (CanLogToElmah(newState))
                {
                    string json = JsonConvert.SerializeObject(audit, Formatting.Indented);
                    new Exception(json).LogToElmah();
                }
            }

            _lastAudit = audit;
        }
        protected virtual void Seed(NoticesContext context)
        {
            var notice = new FuneralNotice(1, "test", "test")
            {
                MemorialId = 1,
                ParentBranchId = "1",
                CedarCode = "cedarCode",
                BranchId = "1",
                KnownAs = "knownAs",
                Obituary = "Obituary",
                Source = SourceType.PERMAVITA,
                DateOfDeath = DateTime.UtcNow,
                DateOfFuneral = DateTime.UtcNow,
            };

            try
            {
                context.FuneralNotices.Add(notice);
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                StringBuilder builder = new StringBuilder();
                foreach (var eve in e.EntityValidationErrors)
                {
                    builder.AppendLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:".Frmt(
                        eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        builder.AppendLine("- Property: \"{0}\", Error: \"{1}\"".Frmt(ve.PropertyName, ve.ErrorMessage));
                    }
                }
                Console.Write(builder.ToString());
                throw;
            }

        }
示例#10
0
        public void Add(FuneralNotice funeralNotice)
        {
            if(funeralNotice.Id < 1)
                throw new ValidationException("Can`t Index notice, with ID=0");

            var notice = new EpiFindNotice(funeralNotice);

            
            _client.Index(notice);
            _logger.Log(funeralNotice, AuditState.Indexed);
            
        }
示例#11
0
 public EpiFindNotice GetNotice(FuneralNotice funeralNotice)
 {
     var notice = new EpiFindNotice(funeralNotice);
     var result = _client.Get<EpiFindNotice>(notice.Id);
     return result;
 }
示例#12
0
        public void Delete(FuneralNotice funeralNotice)
        {
            var notice = new EpiFindNotice(funeralNotice);

            try
            {
                _client.Delete<EpiFindNotice>(notice.Id);
            }
            catch (Exception ex)
            {
                _logger.Log(funeralNotice, new EpiFindException("Delete failed", ex));
            }
        }