public async Task <int> Add(PieDetail pieDetail)
        {
            _appDbContext.PieDetails.Add(pieDetail);
            await _appDbContext.SaveChangesAsync();

            return(pieDetail.PieDetailId);
        }
        public void Delete(int pieDetailId)
        {
            PieDetail pieDetail = _appDbContext.PieDetails.FirstOrDefault(x => x.PieDetailId == pieDetailId);

            pieDetail.IsActive = false;
            //_appDbContext.PieDetails.Remove(pieDetail);
            _appDbContext.SaveChanges();
        }
예제 #3
0
        public Task <int> Update(PieDetail pieDetail)
        {
            PieDetail oldPieDetail = _appDbContext.PieDetails.First(x => x.PieDetailId == pieDetail.PieDetailId);

            _mapper.Map(pieDetail, oldPieDetail);

            return(_appDbContext.SaveChangesAsync());
        }
예제 #4
0
 private PieDetailViewModel MapDbPieDetailToPieDetailViewModel(PieDetail dbPieDetail)
 {
     return(new PieDetailViewModel()
     {
         IsMobile = this.Request.IsMobile(),
         PrimaryPicture = _flickrRepository.GetAlbumPictures(dbPieDetail.FlickrAlbumId).PrimaryPicture,
         PieDetail = dbPieDetail,
         Pies = _pieRepository.ActivePies.Where(x => x.PieDetail.PieDetailId == dbPieDetail.PieDetailId)
     });
 }
        public async Task <IActionResult> AddPieDetail(string name)
        {
            var result = new PieDetail {
                Name = name.ToTitleCase()
            };

            try
            {
                var pieDetail = await _pieDetailRepository.Add(result);

                return(Ok(new { pieDetail }));
            }
            catch
            {
                return(BadRequest());
            }
        }
        //public Dictionary<int, string> TimeEstimations(IEnumerable<Product> products)
        //{
        //    var timeEstimations = new Dictionary<int, string>();
        //    foreach (var time in products.Select(x => x.PreparationTime).Distinct())
        //        timeEstimations.Add(time, _calendar.GetSoonestPickupEstimateForUsers(time));
        //    return timeEstimations;
        //}

        public PieDetailViewModel MapDbPieDetailToPieDetailViewModel(PieDetail dbPieDetail)
        {
            var products = GetChildren(dbPieDetail.PieDetailId);
            // var times = TimeEstimations(products);

            var result = new PieDetailViewModel()
            {
                IsMobile       = _ctx.HttpContext.Request.IsMobile(),
                PrimaryPicture = _flickrRepository.GetAlbumPictures(dbPieDetail.FlickrAlbumId).PrimaryPicture,
                PieDetail      = dbPieDetail,
                Pies           = _pieRepository.ActivePies.Where(x => x.PieDetail.PieDetailId == dbPieDetail.PieDetailId)
            };

            result.Products = products
                              .Select(x => _mapper.Map <Product, ProductEstimationViewModel>(x));
            //.Select(x =>
            //{
            //    x.Estimation = times[x.PreparationTime];
            //    return x;
            //});

            return(result);
        }
예제 #7
0
 public Task <int> Add(PieDetail pieDetail)
 {
     _appDbContext.PieDetails.Add(pieDetail);
     return(_appDbContext.SaveChangesAsync());
 }