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(); }
public Task <int> Update(PieDetail pieDetail) { PieDetail oldPieDetail = _appDbContext.PieDetails.First(x => x.PieDetailId == pieDetail.PieDetailId); _mapper.Map(pieDetail, oldPieDetail); return(_appDbContext.SaveChangesAsync()); }
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); }
public Task <int> Add(PieDetail pieDetail) { _appDbContext.PieDetails.Add(pieDetail); return(_appDbContext.SaveChangesAsync()); }