Example #1
0
        protected override void DoPost(Client currentClient, Product entity, object param)
        {
            HomeConfig config;

            HomeConfigRepository.includes.Add("DefaultBillItemCategoryProduct");
            config = HomeConfigRepository.GetHomeConfigById(entity.HomeId, currentClient.Id);
            if (config != null && config.DefaultBillItemCategoryProduct != null && entity.BillItemCategory == null)
            {
                entity.BillItemCategory = config.DefaultBillItemCategoryProduct;
            }
        }
Example #2
0
        public void DeleteHomeConfig()
        {
            repo.Delete(entity);
            repo.Save();

            Assert.IsNull(ctx.HomeConfigSet.FirstOrDefault(p => p.Home.Id == entity.Id));
            Assert.IsNotNull(ctx.HomeSet.FirstOrDefault(p => p.Id == entity.Id));

            repo.Delete(repo.GetHomeConfigById((int)ctx.HomeSet.FirstOrDefault(p => p.Title == "LaCorderie").Id, (int)ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie").ClientId));
            repo.Save();

            Assert.IsNull(ctx.HomeConfigSet.FirstOrDefault(p => p.Home == ctx.HomeSet.FirstOrDefault(x => x.Title == "LaCorderie")));
            Assert.IsNotNull(ctx.HomeSet.FirstOrDefault(p => p.Title == "LaCorderie"));
        }
Example #3
0
        public virtual MailLog MailSteps(Client currentClient, MailBookingModel model, object param)
        {
            ValidateNull <MailBookingModel>(model);

            MailLog         log             = new MailLog();
            HomeConfig      hc              = null;
            Document        body            = null;
            List <Document> listAttachments = null;

            BookingStepBookingRepository.includes.Add("CurrentStep");
            BookingStepBookingRepository.includes.Add("CurrentStep.Documents");
            BookingStepBookingRepository.includes.Add("CurrentStep.MailTemplate");
            BookingStepBookingRepository.includes.Add("Booking");
            BookingStepBookingRepository.includes.Add("Booking.People");
            BookingStepBooking b = BookingStepBookingRepository.GetBookingStepBookingById(model.BookingId, currentClient.Id);

            if (b == null)
            {
                validationDictionnary.AddModelError(TypeOfName.GetNameFromType <Booking>(), GenericError.FORBIDDEN_RESOURCE_OR_DOES_NO_EXIST);
                throw new ManahostValidationException(validationDictionnary);
            }
            HomeConfigRepository.includes.Add("DefaultMailConfig");
            hc = HomeConfigRepository.GetHomeConfigById(b.HomeId, currentClient.Id);
            if (!((BookingStepBookingValidation)validation).MailStepValidation(validationDictionnary, currentClient, hc, b, model, param))
            {
                throw new ManahostValidationException(validationDictionnary);
            }
            if (b.CurrentStep.MailTemplate == null)
            {
                validationDictionnary.AddModelError("CurrentStep.MailTemplate", GenericError.CANNOT_BE_NULL_OR_EMPTY);
                throw new ManahostValidationException(validationDictionnary);
            }
            body            = DocumentRepository.GetDocumentById(b.CurrentStep.MailTemplate.Id, currentClient.Id);
            listAttachments = b.CurrentStep.Documents;
            if (hc.DefaultMailConfig != null)
            {
                SendMailUsingCustomMailAccount(hc.DefaultMailConfig, b, log, model.Password,
                                               GetMailBody(body, b.Home), MailUtils.GetAttachments(listAttachments, b.Home));
            }
            else
            {
                SendMailUsingManahostMailAccount(b, log, GetMailBody(body, b.Home), MailUtils.GetAttachments(listAttachments, b.Home));
            }
            repo.Add <MailLog>(log);
            repo.Update(b);
            repo.Save();
            return(log);
        }
Example #4
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);
        }