Exemplo n.º 1
0
        //TODO BookingDocument

        protected override Booking DoPostPutDto(Client currentClient, BookingDTO dto, Booking entity, string path, object param)
        {
            if (entity == null)
            {
                entity = new Booking();
            }
            GetMapper.Map <BookingDTO, Booking>(dto, entity);

            HomeConfig hc = HomeConfigRepository.GetHomeConfigById(entity.HomeId, currentClient.Id);

            if (hc != null)
            {
                if (hc.DefaultHourCheckIn != null)
                {
                    entity.DateArrival = ((DateTime)entity.DateArrival).Date.Add(hc.DefaultHourCheckInToTimeSpan);
                }
                if (hc.DefaultHourCheckOut != null)
                {
                    entity.DateDeparture = ((DateTime)entity.DateDeparture).Date.Add(hc.DefaultHourCheckOutToTimeSpan);
                }
            }
            if (dto.People != null)
            {
                entity.People = PeopleService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.People, currentClient, path);
            }
            if (dto.AdditionalBookings != null)
            {
                AdditionalBookingRepository.DeleteRange(entity.AdditionalBookings.Where(d => !dto.AdditionalBookings.Any(x => x.Id == d.Id)));
                dto.AdditionalBookings.ForEach(additionalBooking =>
                {
                    if (entity.AdditionalBookings.Count != 0 && additionalBooking.Id != 0 &&
                        entity.AdditionalBookings.Find(p => p.Id == additionalBooking.Id) != null)
                    {
                        return;
                    }
                    AdditionalBooking toAdd = AdditionalBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, additionalBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.AdditionalBookings.Add(toAdd);
                    }
                });
            }
            if (dto.BookingStepBooking != null)
            {
                entity.BookingStepBooking = BookingStepBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BookingStepBooking, currentClient, path);
            }
            if (dto.Deposits != null)
            {
                DepositRepository.DeleteRange(entity.Deposits.Where(d => !dto.Deposits.Any(x => x.Id == d.Id)));
                dto.Deposits.ForEach(deposit =>
                {
                    if (entity.Deposits.Count != 0 && deposit.Id != 0 &&
                        entity.Deposits.Find(p => p.Id == deposit.Id) != null)
                    {
                        return;
                    }
                    Deposit toAdd = DepositService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, deposit, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.Deposits.Add(toAdd);
                    }
                });
            }
            if (dto.DinnerBookings != null)
            {
                DinnerBookingRepository.DeleteRange(entity.DinnerBookings.Where(d => !dto.DinnerBookings.Any(x => x.Id == d.Id)));
                dto.DinnerBookings.ForEach(dinnerBooking =>
                {
                    if (entity.DinnerBookings.Count != 0 && dinnerBooking.Id != 0 &&
                        entity.DinnerBookings.Find(p => p.Id == dinnerBooking.Id) != null)
                    {
                        return;
                    }
                    DinnerBooking toAdd = DinnerBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dinnerBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.DinnerBookings.Add(toAdd);
                    }
                });
            }
            if (dto.ProductBookings != null)
            {
                ProductBookingRepository.DeleteRange(entity.ProductBookings.Where(d => !dto.ProductBookings.Any(x => x.Id == d.Id)));
                dto.ProductBookings.ForEach(productBooking =>
                {
                    if (entity.ProductBookings.Count != 0 && productBooking.Id != 0 &&
                        entity.ProductBookings.Find(p => p.Id == productBooking.Id) != null)
                    {
                        return;
                    }
                    ProductBooking toAdd = ProductBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, productBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.ProductBookings.Add(toAdd);
                    }
                });
            }
            if (dto.RoomBookings != null)
            {
                RoomBokingRepository.DeleteRange(entity.RoomBookings.Where(d => !dto.RoomBookings.Any(x => x.Id == d.Id)));
                dto.RoomBookings.ForEach(roomBooking =>
                {
                    if (entity.RoomBookings.Count != 0 && roomBooking.Id != 0 &&
                        entity.RoomBookings.Find(p => p.Id == roomBooking.Id) != null)
                    {
                        return;
                    }
                    RoomBooking toAdd = RoomBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, roomBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.RoomBookings.Add(toAdd);
                    }
                });
            }
            entity.DateCreation = DateTime.UtcNow;
            return(entity);
        }
Exemplo n.º 2
0
 public void Init()
 {
     ctx    = EFContext.CreateContext();
     repo   = new AdditionalBookingRepository(ctx);
     entity = new AdditionalBooking()
     {
         BillItemCategory = new BillItemCategory()
         {
             DateModification = DateTime.Now,
             Home             = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
             Title            = "EFTest"
         },
         Booking = new Booking()
         {
             Comment            = "I am a comment",
             DateArrival        = DateTime.Now.AddYears(1),
             DateCreation       = DateTime.Now,
             DateDeparture      = DateTime.Now.AddYears(3),
             DateDesiredPayment = DateTime.Now.AddYears(3).AddMonths(1),
             DateModification   = DateTime.Now,
             DateValidation     = DateTime.Now.AddMonths(4),
             Home                 = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
             IsOnline             = false,
             IsSatisfactionSended = false,
             People               = new People()
             {
                 AcceptMailing = true,
                 Addr          = "4 place kleber",
                 City          = "Strasbourg",
                 Civility      = "Mr",
                 Comment       = "A mis le feu à la chambre",
                 Country       = "FRANCE",
                 DateBirth     = DateTime.Now,
                 DateCreation  = DateTime.Now,
                 Email         = "*****@*****.**",
                 Firstname     = "CHAABANE",
                 Home          = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
                 Lastname      = "Jalal",
                 Mark          = 0,
                 Phone1        = "0600000000",
                 Phone2        = null,
                 State         = null,
                 ZipCode       = "67000",
                 Hide          = false
             },
             TotalPeople = 4
         },
         DateModification = DateTime.Now,
         Home             = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
         PriceHT          = 999M,
         PriceTTC         = 999M,
         Tax = new Tax()
         {
             DateModification = DateTime.Now,
             Home             = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
             Price            = 50M,
             Title            = "EFTest",
             ValueType        = EValueType.PERCENT
         },
         Title = "EFTest"
     };
 }
 public void Init()
 {
     ctx = EFContext.CreateContext();
     repo = new AdditionalBookingRepository(ctx);
     entity = new AdditionalBooking()
     {
         BillItemCategory = new BillItemCategory()
         {
             DateModification = DateTime.Now,
             Home = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
             Title = "EFTest"
         },
         Booking = new Booking()
         {
             Comment = "I am a comment",
             DateArrival = DateTime.Now.AddYears(1),
             DateCreation = DateTime.Now,
             DateDeparture = DateTime.Now.AddYears(3),
             DateDesiredPayment = DateTime.Now.AddYears(3).AddMonths(1),
             DateModification = DateTime.Now,
             DateValidation = DateTime.Now.AddMonths(4),
             Home = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
             IsOnline = false,
             IsSatisfactionSended = false,
             People = new People()
             {
                 AcceptMailing = true,
                 Addr = "4 place kleber",
                 City = "Strasbourg",
                 Civility = "Mr",
                 Comment = "A mis le feu à la chambre",
                 Country = "FRANCE",
                 DateBirth = DateTime.Now,
                 DateCreation = DateTime.Now,
                 Email = "*****@*****.**",
                 Firstname = "CHAABANE",
                 Home = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
                 Lastname = "Jalal",
                 Mark = 0,
                 Phone1 = "0600000000",
                 Phone2 = null,
                 State = null,
                 ZipCode = "67000",
                 Hide = false
             },
             TotalPeople = 4
         },
         DateModification = DateTime.Now,
         Home = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
         PriceHT = 999M,
         PriceTTC = 999M,
         Tax = new Tax()
         {
             DateModification = DateTime.Now,
             Home = ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie"),
             Price = 50M,
             Title = "EFTest",
             ValueType = EValueType.PERCENT
         },
         Title = "EFTest"
     };
 }