Пример #1
0
        public IActionResult Post([FromBody] DeathDate deathDateNew)
        {
            if (deathDateNew.IsObjectNull())
            {
                return(BadRequest(new { Message = "DeathDate object is null" }));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Message = "Invalid model object" }));
            }
            try
            {
                var secuence = this.deathDateBR.CreateDate(deathDateNew);
                if (!secuence)
                {
                    return(BadRequest(new { Message = "DeathDate Object is not Created" }));
                }
                if (deathDateNew.IsEmptyObject())
                {
                    return(BadRequest(new { Message = "DeathDate Object is not Created" }));
                }

                return(CreatedAtRoute("DeathDateById", new { id = deathDateNew.Id }, deathDateNew));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new { Message = $"Internal server error: {ex.Message}" }));
            }
        }
        public void Configure(EntityTypeBuilder <Author> builder)
        {
            builder.ToTable("Author").HasKey(k => k.Id);

            builder.OwnsOne(p => p.Name, p =>
            {
                p.Property(pp => pp.First).HasColumnName("FirstName").IsRequired().HasMaxLength(50);
                p.Property(pp => pp.Last).HasColumnName("LastName").IsRequired().HasMaxLength(50);
            });

            builder.Property(p => p.DateOfBirth)
            .IsRequired()
            .HasConversion(p => p.Value, p => BirthDate.Create(p).Value);

            builder.Property(p => p.DateOfDeath)
            .HasConversion(p => p.Value, p => DeathDate.Create(p).Value);

            builder.Property(p => p.MainCategory)
            .IsRequired()
            .HasMaxLength(50)
            .HasConversion(p => p.Value, p => MainCategory.Create(p).Value);

            builder.HasMany(p => p.Books).WithOne(p => p.Author)
            .OnDelete(DeleteBehavior.Cascade)
            .Metadata.PrincipalToDependent.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Пример #3
0
 public static void Map(this DeathDate dbDeathDate, DeathDate deathDate)
 {
     dbDeathDate.Start        = deathDate.Start;
     dbDeathDate.End          = deathDate.End;
     dbDeathDate.Title        = deathDate.Title;
     dbDeathDate.ContactEmail = deathDate.ContactEmail;
 }
Пример #4
0
        public IActionResult Put(Guid id, [FromBody] DeathDate deathDate)
        {
            try
            {
                if (id.Equals(Guid.Empty))
                {
                    return(BadRequest(new { Message = "Id is Empty" }));
                }
                if (deathDate.IsObjectNull())
                {
                    return(BadRequest(new { Message = "DeathDate Object is Null" }));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new { Message = "Invalid model object" }));
                }

                bool secuence = this.deathDateBR.UdpdateDate(id, deathDate);

                if (!secuence)
                {
                    return(NotFound());
                }

                return(Ok(deathDate));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new { Message = $"Internal server error: {ex.Message}" }));
            }
        }
 public void Customize(IFixture fixture)
 {
     fixture.Customizations.Add(new CurrentDateTimeGenerator());
     fixture.Register(() => Name.Create(fixture.Create <string>(), fixture.Create <string>()).Value);
     fixture.Register(() => BirthDate.Create(fixture.Create <DateTimeOffset>().AddDays(-fixture.Create <int>())).Value);
     fixture.Register(() => DeathDate.Create(fixture.Create <DateTimeOffset>().AddDays(-fixture.Create <int>())).Value);
     fixture.Register(() => MainCategory.Create(fixture.Create <string>()).Value);
 }
Пример #6
0
        static model.DeceasedPerson isDead(model.Person person, Person localPerson)
        {
            var deceasedPerson = new model.DeceasedPerson
            {
                Person      = person,
                DateOfDeath = DeathDate.getDeathDate(localPerson.BirthDate)
            };

            return(deceasedPerson);
        }
Пример #7
0
        /// <summary>
        /// Get all the key=value pairs (pins) exposed by the implementor.
        /// </summary>
        /// <param name="item">The optional item. The item with its parts
        /// can optionally be passed to this method for those parts requiring
        /// to access further data.</param>
        /// <returns>The pins.</returns>
        public override IEnumerable <DataPin> GetDataPins(IItem item)
        {
            DataPinBuilder builder = new DataPinBuilder(
                DataPinHelper.DefaultFilter);

            builder.AddValue("id", PrisonerId);
            builder.AddValue("prison-id", PrisonId);
            if (Sex != '\0')
            {
                builder.AddValue("sex", new string(Sex, 1));
            }
            if (Name != null)
            {
                builder.AddValue("name",
                                 DataPinHelper.DefaultFilter.Apply(Name.GetFullName(), true));
            }

            if (BirthDate != null)
            {
                builder.AddValue("birth-value", BirthDate.GetSortValue());
            }

            if (DeathDate != null)
            {
                builder.AddValue("death-value", DeathDate.GetSortValue());
            }

            if (!string.IsNullOrEmpty(Origin))
            {
                builder.AddValue("origin", Origin, filter: true, filterOptions: true);
            }

            if (!string.IsNullOrEmpty(Charge))
            {
                builder.AddValue("charge", Charge, filter: true, filterOptions: true);
            }

            if (!string.IsNullOrEmpty(Judgement))
            {
                builder.AddValue("judgement", Judgement, filter: true, filterOptions: true);
            }

            if (DetentionStart != null)
            {
                builder.AddValue("det-start-value", DetentionStart.GetSortValue());
            }

            if (DetentionEnd != null)
            {
                builder.AddValue("det-end-value", DetentionEnd.GetSortValue());
            }

            return(builder.Build(this));
        }
Пример #8
0
 /// <summary>
 /// Generates the properties value for this node.
 /// </summary>
 /// <returns></returns>
 public virtual Dictionary <string, object> GetPropertyMap()
 {
     return(new Dictionary <string, object>
     {
         { "id", Id.ToString() },
         { "commonName", CommonName },
         { "othernames", OtherNames },
         { "releaseDate", ReleaseDate?.ToString("yyyy-MM-dd") },
         { "deathDate", DeathDate?.ToString("yyyy-MM-dd") }
     });
 }
Пример #9
0
        public void Create_DeathDate_Should_Fail_For_NullDate()
        {
            //Arrange
            DateTimeOffset?deathDate = null;

            //Act
            var result = DeathDate.Create(deathDate);

            //Assert
            result.IsFailure.Should().BeTrue();
            result.Error.Should().Be("Death Date should not be null.");
        }
Пример #10
0
        public String GetFullAuthor()
        {
            String authorStr = String.Format("'{0} {1}' \n--> Born the : {2}", FirstName, LastName, BirthDate.ToLongDateString());

            if (DeathDate != null)
            {
                authorStr += String.Format("\n--> Died the : {0}", DeathDate.ToString());
            }

            authorStr += String.Format("\n--> Nationality : {0} - {1}", Nationality.ToString(), EnumHelpers.ToDescriptionString(Nationality));

            return(authorStr);
        }
Пример #11
0
        public bool UdpdateDate(Guid dateId, DeathDate deathDateUpdated)
        {
            try
            {
                var dbDeathDate = this.repository.DeathDate.GetDateById(dateId);
                if (dbDeathDate.IsEmptyObject() || dbDeathDate.IsObjectNull())
                {
                    return(false);
                }
                if (dbDeathDate.Start != deathDateUpdated.Start || dbDeathDate.End != deathDateUpdated.End)
                {
                    if (!this.IsOfficeHours(deathDateUpdated.Start) || !this.IsOfficeHours(deathDateUpdated.End))
                    {
                        return(false);
                    }
                    if (this.IsWeekend(deathDateUpdated.Start) || this.IsWeekend(deathDateUpdated.End))
                    {
                        return(false);
                    }
                    if (this.IsDifferentDay(deathDateUpdated.Start, deathDateUpdated.End))
                    {
                        return(false);
                    }
                    if (this.DiffHoursInSeconds(deathDateUpdated.Start, deathDateUpdated.End) > 3600)
                    {
                        return(false);
                    }

                    var deathDatesFind = this.repository.DeathDate.GetAllDateBetween(deathDateUpdated.Start, deathDateUpdated.End, dateId);
                    if (deathDatesFind != null)
                    {
                        if (deathDatesFind.Count() > 0)
                        {
                            return(false);
                        }
                    }
                }

                this.repository.DeathDate.UpdateDate(dbDeathDate, deathDateUpdated);
                this.repository.Save();

                deathDateUpdated.Id = dateId;

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Пример #12
0
        public void Create_DeathDate_Should_Create_For_PastDate()
        {
            //Arrange
            var fixture = new Fixture();

            fixture.Customizations.Add(new CurrentDateTimeGenerator());
            var deathDate = fixture.Create <DateTimeOffset>().AddDays(-fixture.Create <int>());

            //Act
            var result = DeathDate.Create(deathDate);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.Value.Value.Should().BeSameDateAs(deathDate);
        }
Пример #13
0
        public void Create_DeathDate_Should_Fail_For_FutureDate()
        {
            //Arrange
            var fixture = new Fixture();

            fixture.Customizations.Add(new CurrentDateTimeGenerator());
            var deathDate = fixture.Create <DateTimeOffset>().AddDays(fixture.Create <int>());

            //Act
            var result = DeathDate.Create(deathDate);

            //Assert
            result.IsFailure.Should().BeTrue();
            result.Error.Should().Be("Death Date should not be future date.");
        }
Пример #14
0
        private bool ValidateInputs()
        {
            if (string.IsNullOrEmpty(BirthFullName.Text))
            {
                BirthFullName.Focus();
                return(false);
            }

            if (DeathDate.Checked && BirthDate.Value >= DeathDate.Value)
            {
                DeathDate.Focus();
                return(false);
            }

            return(true);
        }
Пример #15
0
 protected override Saint Parse()
 {
     return(new Saint
     {
         Id = Convert.ToInt64(SaintID),
         Name = Name.ToString(),
         Biography = Biography.ToString(),
         FeastDay = FeastDay.ToString(),
         Categories = Categories.ToString(),
         BirthDate = BirthDate.ToString(),
         DeathDate = DeathDate.ToString(),
         CanonizeDate = CanonizeDate.ToString(),
         RelatedChurch = RelatedChurch.ToString(),
         Patron = Patron.ToString(),
         ImagePath = ImagePath.ToString(),
         PublicationDate = ToDateTime(PublicationDate)
     });
 }
Пример #16
0
 public IActionResult CreateConfirmed(DeathDateCEViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (UnitOfWork.DeathDateDal.GetQueryable().FirstOrDefault(p => p.Year == model.Year) == null)
         {
             var deathDate = new DeathDate()
             {
                 Id   = Guid.NewGuid(),
                 Year = model.Year
             };
             UnitOfWork.DeathDateDal.Add(deathDate);
             UnitOfWork.Commit();
             return(RedirectToAction("Index", "DeathDate"));
         }
     }
     return(RedirectToAction("Index", "DeathDate"));
 }
            public async Task <Result <Author> > Handle(CreateAuthorWithDeathDateCommand command)
            {
                var nameResult         = Name.Create(command.FirstName, command.LastName);
                var birthDateResult    = BirthDate.Create(command.DateOfBirth);
                var deathDateResult    = DeathDate.Create(command.DateOfDeath);
                var mainCategoryResult = Entities.Authors.MainCategory.Create(command.MainCategory);

                var authorResult = Result.Combine(nameResult, birthDateResult, deathDateResult, mainCategoryResult)
                                   .Ensure(() => birthDateResult.Value.Value.Date < deathDateResult.Value.Value.Value.Date, "Death date should not be less than birth date.")
                                   .Map(() => new Author(nameResult.Value, birthDateResult.Value, deathDateResult.Value, mainCategoryResult.Value));

                if (authorResult.IsFailure)
                {
                    return(Result.Failure <Author>(authorResult.Error));
                }

                await _unitOfWork.AuthorRepository.AddAsync(authorResult.Value).ConfigureAwait(false);

                await _unitOfWork.SaveChangesAsync().ConfigureAwait(false);

                return(Result.Success(authorResult.Value));
            }
Пример #18
0
        public bool CreateDate(DeathDate deathDateNew)
        {
            try
            {
                if (!this.IsOfficeHours(deathDateNew.Start) || !this.IsOfficeHours(deathDateNew.End))
                {
                    return(false);
                }
                if (this.IsWeekend(deathDateNew.Start) || this.IsWeekend(deathDateNew.End))
                {
                    return(false);
                }
                if (this.IsDifferentDay(deathDateNew.Start, deathDateNew.End))
                {
                    return(false);
                }
                if (this.DiffHoursInSeconds(deathDateNew.Start, deathDateNew.End) > 3600)
                {
                    return(false);
                }

                var deathDatesFind = this.repository.DeathDate.GetAllDateBetween(deathDateNew.Start, deathDateNew.End);
                if (deathDatesFind != null)
                {
                    if (deathDatesFind.Count() > 0)
                    {
                        return(false);
                    }
                }

                this.repository.DeathDate.CreateDate(deathDateNew);
                this.repository.Save();
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Пример #19
0
            public async Task <Result <Author> > Handle(CreateAuthorWithDeathDateCommand command)
            {
                Result <Name> nameResult = Name.Create(command.FirstName, command.LastName);

                if (nameResult.IsFailure)
                {
                    return(Result.Failure <Author>(nameResult.Error));
                }

                Result <BirthDate> birthDateResult = BirthDate.Create(command.DateOfBirth);

                if (birthDateResult.IsFailure)
                {
                    return(Result.Failure <Author>(birthDateResult.Error));
                }

                Result <DeathDate> deathDateResult = DeathDate.Create(command.DateOfDeath);

                if (deathDateResult.IsFailure)
                {
                    return(Result.Failure <Author>(deathDateResult.Error));
                }

                Result <MainCategory> mainCategoryResult = Entities.Authors.MainCategory.Create(command.MainCategory);

                if (mainCategoryResult.IsFailure)
                {
                    return(Result.Failure <Author>(mainCategoryResult.Error));
                }

                var author = new Author(nameResult.Value, birthDateResult.Value, deathDateResult.Value, mainCategoryResult.Value);

                await _unitOfWork.AuthorRepository.AddAsync(author);

                await _unitOfWork.SaveChangesAsync();

                return(Result.Success(author));
            }
Пример #20
0
 public override string ToString()
 {
     return(String.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n", FirstName, LastName, Patronymic, BirthDate.ToString("dd/MM/yyyy"), IsDead ? "1" : "0", DeathDate.ToString("dd/MM/yyyy"), Profession));
 }
Пример #21
0
 public override string ToString()
 {
     return("ID: " + CharacterDeathID.ToString() + "   Name: " + DeathDate.ToString());
 }