using Admin.Core.IRepository; using Admin.Core.Service; using Admin.Core.IService; using Admin.Core.Model; using System.Threading.Tasks; using System.Collections.Generic; using System; using Serilog; using NPOI.SS.Formula.Functions; using System.Linq; using Microsoft.Extensions.Logging; namespace Admin.Core.Service { public class xl_recipeServices : BaseServices, Ixl_recipeServices { private readonly IBaseRepository _dal; public xl_recipeServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } public async Task> xlGetAllRecipes() { try { return await _dal.QueryAsync(); } catch(Exception ex) { throw; } } public async Task xlInsertRecipe(xl_recipe recipe) { try { if(await _dal.AddAsync(recipe) == 1) { return true; } else { return false; } } catch(Exception ex) { throw; } } public async Task xlUpdateRecipe(xl_recipe recipe) { try { return await _dal.UpdateAsync(recipe); } catch(Exception ex) { throw; } } public async Task xlUpdateOrAdd(xl_recipe recipe) { try { var record = await _dal.QueryAsync(x => x.Recipe_Code == recipe.Recipe_Code); if(record == null || record.Count == 0) { recipe.ID = record[0].ID; return await xlUpdateRecipe(recipe); } else { return await xlInsertRecipe(recipe); } } catch (Exception ex) { throw; } } } }