Пример #1
0
        protected override Meal DoPostPutDto(Client currentClient, MealDTO dto, Meal entity, string path, object param)
        {
            if (entity == null)
            {
                entity = new Meal();
            }
            else
            {
                if (dto.RefHide == null)
                {
                    dto.RefHide = entity.RefHide;
                }
            }
            GetMapper.Map(dto, entity);
            if (dto.BillItemCategory != null)
            {
                entity.BillItemCategory = BillitemCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BillItemCategory, currentClient, path);
            }
            if (dto.Documents != null)
            {
                DocumentRepository.DeleteRange(entity.Documents.Where(d => !dto.Documents.Any(x => x.Id == d.Id)));
                dto.Documents.ForEach(document =>
                {
                    if (entity.Documents.Count != 0 && document.Id != 0 &&
                        entity.Documents.Find(p => p.Id == document.Id) != null)
                    {
                        return;
                    }
                    Document toAdd = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, document, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.Documents.Add(toAdd);
                    }
                });
            }
            if (dto.MealCategory != null)
            {
                entity.MealCategory = MealCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.MealCategory, currentClient, path);
            }
            if (dto.MealPrices != null)
            {
                MealPrice.DeleteRange(entity.MealPrices.Where(d => !dto.MealPrices.Any(x => x.Id == d.Id)));
                dto.MealPrices.ForEach(mealPrice =>
                {
                    if (entity.MealPrices.Count != 0 && mealPrice.Id != 0 &&
                        entity.MealPrices.Find(p => p.Id == mealPrice.Id) != null)
                    {
                        return;
                    }
                    MealPrice toAdd = MealPriceService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, mealPrice, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.MealPrices.Add(toAdd);
                    }
                });
            }
            return(entity);
        }
Пример #2
0
        public void DeleteMeal()
        {
            MealPrice toDelete = ctx.MealPriceSet.FirstOrDefault(p => p.PriceHT == 15M);

            repo.Delete(toDelete);
            repo.Save();

            Assert.IsNull(ctx.MealPriceSet.FirstOrDefault(p => p.PriceHT == 15M));
            Assert.IsNotNull(ctx.PeopleCategorySet.FirstOrDefault(p => p.Label == "Adultes"));
            Assert.IsNotNull(ctx.MealSet.FirstOrDefault(p => p.Title == "Meal1"));
        }
Пример #3
0
        public virtual DinnerBookingDTO Compute(Client currentClient, int id, object param)
        {
            Decimal priceHT  = 0;
            Decimal priceTTC = 0;
            IEnumerable <MealBooking> mealBookings = null;

            ProcessDTOPostPut(null, id, currentClient);
            ValidateOrig();
            repo.includes.Add("PeopleCategory");
            repo.includes.Add("Meal");
            mealBookings = repo.GetAllMealByDinnerBooking(id, currentClient.Id);
            foreach (MealBooking cur in mealBookings)
            {
                repo.includes.Add("Tax");
                MealPrice priceForMeal = repo.GetMealPriceByPeopleCategoryId(cur.PeopleCategory.Id, (int)cur.Meal.Id, currentClient.Id);
                if (priceForMeal == null)
                {
                    validationDictionnary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <DinnerBooking>(), "MealPrice"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
                    throw new ManahostValidationException(validationDictionnary);
                }
                Decimal tmpPrice = (Decimal)priceForMeal.PriceHT * (int)cur.NumberOfPeople;

                priceHT += tmpPrice;
                if (priceForMeal.Tax != null)
                {
                    priceTTC += ComputePrice.ComputePriceFromPercentOrAmount(tmpPrice, (EValueType)priceForMeal.Tax.ValueType,
                                                                             (EValueType)priceForMeal.Tax.ValueType == EValueType.AMOUNT ? (Decimal)priceForMeal.Tax.Price * (int)cur.NumberOfPeople : (Decimal)priceForMeal.Tax.Price);
                }
                else
                {
                    priceTTC += tmpPrice;
                }
            }
            orig.PriceHT  = priceHT;
            orig.PriceTTC = priceTTC;
            repo.Update(orig);
            repo.Save();
            return(GetMapper.Map <DinnerBooking, DinnerBookingDTO>(orig));
        }