Example #1
0
        public static PersonDTO ToDTO(this Person entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var result = new PersonDTO() { ID = entity.ID };

            if (entity.Avatars.Count > 0)
            {
                Avatar activeAvatar = entity.Avatars.SingleOrDefault(x => x.IsActive);

                result.AvatarUrl = activeAvatar != null ? activeAvatar.AvatarPath : string.Empty;
            }

            result.DOB = entity.DOB;
            result.QQ = !string.IsNullOrEmpty(entity.QQ) ? entity.QQ : string.Empty;
            result.RealName = !string.IsNullOrEmpty(entity.RealName) ? entity.RealName : string.Empty;
            result.NickName = !string.IsNullOrEmpty(entity.NickName) ? entity.NickName : string.Empty;
            result.HomePage = !string.IsNullOrEmpty(entity.HomePage) ? entity.HomePage : string.Empty;
            result.AvatarUrl = !string.IsNullOrEmpty(result.AvatarUrl) ? result.AvatarUrl : string.Empty;
            result.Introduction = !string.IsNullOrEmpty(entity.Introduction) ? entity.Introduction : string.Empty;
            result.Gender = entity.Gender != null ? entity.Gender.GetDescription() : string.Empty;
            result.SexualTrend = entity.SexualTrend != null ? entity.SexualTrend.GetDescription() : string.Empty;
            result.MaritalStatus = entity.MaritalStatus != null ? entity.MaritalStatus.GetDescription() : string.Empty;
            result.BloodType = entity.BloodType != null ? entity.BloodType.GetDescription() : string.Empty;
            result.FollowingCount = entity.MyFollowingPersons.Count;
            result.FansCount = entity.MyFans.Count;
            result.BlogCount = entity.Blogs.Count(x => !x.IsDeleted);

            return result;
        }
Example #2
0
        public void CreateUser(PersonDTO person)
        {
            using (DataAccessLayer dal = new EFDataAccessLayer())
            {
                AccountDTO accountDto = dal.AccountDAO.Create(new AccountDTO(null, 0, dal));
                //piwi devia ser assim (bem mais simples): person.Account = accountDto;
                //person.AccountID = accountDto.ID.GetValueOrDefault(0);

                dal.PersonDAO.Create(person);
            }
        }
        public void Should_honor_datamember_attribute()
        {
            var person = new PersonDTO
            {
                Id = 123,
                Name = "Abc"
            };

            Assert.That(TypeSerializer.SerializeToString(person), Is.EqualTo("{Id:123,Name:Abc}"));
            Assert.That(JsonSerializer.SerializeToString(person), Is.EqualTo("{\"Id\":123,\"Name\":\"Abc\"}"));
        }
Example #4
0
        private static void CreatePerson()
        {
            Console.WriteLine("Last Name ?");
            var lastName = Console.ReadLine();

            Console.WriteLine("First Name ?");
            var name = Console.ReadLine();

            Console.WriteLine("Username ?");
            var username = Console.ReadLine();

            Console.WriteLine("Password ?");
            var password = Console.ReadLine();

            Console.WriteLine("Email ?");
            var email = Console.ReadLine();

            var person = new PersonDTO { Username = username, Password = password, Name = name, LastName = lastName, Email = email };
            service.InsertPerson(person);
            Console.WriteLine("Person created !");
        }
Example #5
0
        private static void Initialize()
        {
            var type = service.GetAllTypeEvent();
            if (!type.Any())
            {
                var typeEvents = new List<TypeEventDTO>
                {
                    new TypeEventDTO {TypeEventId = 1, Name = "Party"},
                    new TypeEventDTO {TypeEventId = 2,Name = "Seminar"},
                };

                typeEvents.ForEach(x => service.InsertTypeEvent(x));
            }

            var status = service.GetAllStatusEvent();
            if (!status.Any())
            {
                var statusEvents = new List<StatusEventDTO>
                {
                    new StatusEventDTO {StatusEventId = 1, Name = "Pending"},
                    new StatusEventDTO {StatusEventId = 2, Name = "Open"},
                    new StatusEventDTO {StatusEventId = 3, Name = "Close"},
                };

                statusEvents.ForEach(x => service.InsertStatusEvent(x));
            }

            var persons = service.GetAllPerson();
            if (!persons.Any())
            {
                var person = new PersonDTO {PersonId = 1, Username = "******", Password = "******", Name = "Toto", LastName = "Dupont", Email = "*****@*****.**"};
                service.InsertPerson(person);
            }

            var events = service.GetAllEvent();
            if (!events.Any())
            {
                var date = new DateTime(2014, 10, 10);
                var person = service.GetAllPerson().FirstOrDefault();
                var party = service.GetTypeEventByName("Party");
                var pending = service.GetStatusEventByName("Pending");
                var closed = service.GetStatusEventByName("Close");

                var eventsList = new List<EventDTO>
                {
                    new EventDTO {EventId = 1, Name = "Event1", Address = "Address1", Description = "Desc1", Date = date, CreatorId = person.PersonId, TypeEventId = party.TypeEventId, StatusEventId = pending.StatusEventId},
                    new EventDTO {EventId = 2, Name = "Event2", Address = "Address2", Description = "Desc2", Date = date, CreatorId = person.PersonId, TypeEventId = party.TypeEventId, StatusEventId = pending.StatusEventId},
                    new EventDTO {EventId = 3, Name = "Event3", Address = "Address3", Description = "Desc3", Date = date, CreatorId = person.PersonId, TypeEventId = party.TypeEventId, StatusEventId = closed.StatusEventId},
                    new EventDTO {EventId = 4, Name = "Event4", Address = "Address4", Description = "Desc4", Date = date, CreatorId = person.PersonId, TypeEventId = party.TypeEventId, StatusEventId = closed.StatusEventId},
                };

                eventsList.ForEach(x => service.InsertEvent(x));
            }

            var typeContributions = service.GetAllTypeContribution();
            if (!typeContributions.Any())
            {
                var typeContribution = new TypeContributionDTO {TypeContributionId = 1, Name = "Food & Drink"};
                service.InsertTypeContribution(typeContribution);
            }

            var contributions = service.GetAllContribution();
            if (!contributions.Any())
            {
                var person = service.GetAllPerson().FirstOrDefault();
                var event1 = service.GetEventByName("Event1").FirstOrDefault();
                var event2 = service.GetEventByName("Event2").FirstOrDefault();
                var typeContribution = service.GetTypeContributionByName("Food & Drink");

                var contribution = new List<ContributionDTO>
                {
                    new ContributionDTO {ContributionId = 1, Name = "Cake", Quantity = "1", TypeContributionId = typeContribution.TypeContributionId, PersonId = person.PersonId, EventId = event1.EventId},
                    new ContributionDTO {ContributionId = 2, Name = "Drinks", Quantity = "2", TypeContributionId = typeContribution.TypeContributionId, PersonId = person.PersonId, EventId = event1.EventId},
                    new ContributionDTO {ContributionId = 3, Name = "Musics", Quantity = "3", TypeContributionId = typeContribution.TypeContributionId, PersonId = person.PersonId, EventId = event1.EventId},
                    new ContributionDTO {ContributionId = 4, Name = "Alcohols", Quantity = "4", TypeContributionId = typeContribution.TypeContributionId, PersonId = person.PersonId, EventId = event2.EventId},
                };

                contribution.ForEach(x => service.InsertContribution(x));
            }
        }
Example #6
0
 public void UpdateFrom(PersonDTO source, EntityUpdateOptions options = null)
 {
     Name = source.Name;
 }