public static DishModelDto GetDishModelDto(this IRepositoryAsync <MfdDishPriceRelations> repository, Dish dish,
                                                   int?menufordayid = null)
        {
            DishModelDto dto   = null;
            double       price = 0.00;

            if (menufordayid == null)
            {
                price = dish.CurrentPrice.Price;
            }
            else
            {
                MfdDishPriceRelations first =
                    repository.Query()
                    .Include(mp => mp.DishPrice)
                    .Select()
                    .FirstOrDefault(mfdpr => mfdpr.DishId == dish.DishID && mfdpr.MenuForDayId == menufordayid);
                if (first != null)
                {
                    price = first.DishPrice.Price;
                }
            }
            dto = new DishModelDto
            {
                DishId       = dish.DishID,
                Title        = dish.Title /*?? "Блюдо не выбрано"*/,
                ProductImage = dish.ProductImage,
                Price        = price,
                Category     = dish.DishType.Category,
                Description  = dish.Description,
                Deleted      = dish.Deleted
            };
            return(dto);
        }
 public static DishModelDto GetDishModelDto(this IRepositoryAsync<MfdDishPriceRelations> repository, Dish dish,
     int? menufordayid = null)
 {
     DishModelDto dto = null;
     double price = 0.00;
     if (menufordayid == null)
     {
         price = dish.CurrentPrice.Price;
     }
     else
     {
         MfdDishPriceRelations first =
             repository.Query()
                 .Include(mp => mp.DishPrice)
                 .Select()
                 .FirstOrDefault(mfdpr => mfdpr.DishId == dish.DishID && mfdpr.MenuForDayId == menufordayid);
         if (first != null)
         {
             price = first.DishPrice.Price;
         }
     }
     dto = new DishModelDto
     {
         DishId = dish.DishID,
         Title = dish.Title /*?? "Блюдо не выбрано"*/,
         ProductImage = dish.ProductImage,
         Price = price,
         Category = dish.DishType.Category,
         Description = dish.Description,
         Deleted = dish.Deleted
     };
     return dto;
 }
        public static void InsertDish(this IRepositoryAsync <MfdDishPriceRelations> repository, DishModelDto dishmodel)
        {
            Dish newdish = new Dish
            {
                Title        = dishmodel.Title,
                CurrentPrice = repository.GetDishPrice(dishmodel.Price),
                Description  = dishmodel.Description,
                ProductImage = dishmodel.ProductImage,
                DishType     =
                    repository.GetRepositoryAsync <DishType>()
                    .Queryable()
                    .FirstOrDefault(dt => string.Equals(dt.Category, dishmodel.Category))
            };

            repository.Context.Entry(newdish).State = EntityState.Added;
        }
        public static void UpdateDish(this IRepositoryAsync <MfdDishPriceRelations> repository, DishModelDto dish)
        {
            Dish updish = repository.GetRepositoryAsync <Dish>().Find(dish.DishId);

            updish.Description  = dish.Description;
            updish.Title        = dish.Title;
            updish.CurrentPrice = repository.GetDishPrice(dish.Price);
            repository.Context.Entry(updish).State = EntityState.Modified;
        }
Пример #5
0
 public void InsertDish(DishModelDto dish)
 {
     _repository.InsertDish(dish);
 }
Пример #6
0
 public void UpdateDish(DishModelDto dish)
 {
     _repository.UpdateDish(dish);
 }
 public static void UpdateDish(this IRepositoryAsync<MfdDishPriceRelations> repository, DishModelDto dish)
 {
     Dish updish = repository.GetRepositoryAsync<Dish>().Find(dish.DishId);
     updish.Description = dish.Description;
     updish.Title = dish.Title;
     updish.CurrentPrice = repository.GetDishPrice(dish.Price);
     repository.Context.Entry(updish).State = EntityState.Modified;
 }
 public static void InsertDish(this IRepositoryAsync<MfdDishPriceRelations> repository, DishModelDto dishmodel)
 {
     Dish newdish = new Dish
     {
         Title = dishmodel.Title,
         CurrentPrice = repository.GetDishPrice(dishmodel.Price),
         Description = dishmodel.Description,
         ProductImage = dishmodel.ProductImage,
         DishType =
             repository.GetRepositoryAsync<DishType>()
                 .Queryable()
                 .FirstOrDefault(dt => string.Equals(dt.Category, dishmodel.Category))
     };
     repository.Context.Entry(newdish).State = EntityState.Added;
 }