public async Task <ActionResult <int> > PostFeedingFigure(PostFeedingFiguresRequest request) { return(await _feedingFiguresLogic.SaveFeedingFigure(request)); }
public async Task <int> SaveFeedingFigure(PostFeedingFiguresRequest request) { if (request.FeedingNumber != null) { request.FeedingNumber = Convert.ToInt32(request.FeedingNumber); } var figures = await _repo.FindAsync <AdmSitesFeedingFigure>(request.AdmSiteId); if (figures == null) { //insert AdmSitesFeedingFigure newFigures = new AdmSitesFeedingFigure { AdmSiteID = request.AdmSiteId }; switch (request.FeedingName) { case "Breakfast": newFigures.Breakfast = request.FeedingNumber; break; case "Lunch": newFigures.Lunch = request.FeedingNumber; break; case "Snack": newFigures.Snack = request.FeedingNumber; break; case "Supper": newFigures.Supper = request.FeedingNumber; break; } await _repo.CreateAsync(newFigures); return(newFigures.AdmSiteID); } else { //update switch (request.FeedingName) { case "Breakfast": figures.Breakfast = request.FeedingNumber; break; case "Lunch": figures.Lunch = request.FeedingNumber; break; case "Snack": figures.Snack = request.FeedingNumber; break; case "Supper": figures.Supper = request.FeedingNumber; break; } await _repo.UpdateAsync(figures); return(figures.AdmSiteID); } }