public BeerType GetBeerTypetByName(string BeerType) { using (var ctx = new BrewAreaEntities()) { return(ctx.BeerTypes.Where(t => t.BeerType1 == BeerType).SingleOrDefault()); } }
public MeasurementType GetMeasurementByName(string measurementType) { using (var ctx = new BrewAreaEntities()) { return(ctx.MeasurementTypes.Where(t => t.MeasurementType1 == measurementType).SingleOrDefault()); } }
public MeasurementType GetMeasurementType(int measurementTypeId) { using (var ctx = new BrewAreaEntities()) { return(ctx.MeasurementTypes.Where(t => t.MeasurementTypeId == measurementTypeId).SingleOrDefault()); } }
public List <MeasurementType> GetAllMeasurements() { using (var ctx = new BrewAreaEntities()) { return(ctx.MeasurementTypes.ToList()); } }
public Ingredient GetByName(string ingredientName) { using (var ctx = new BrewAreaEntities()) { return(ctx.Ingredients.Where(t => t.Name == ingredientName).SingleOrDefault()); } }
public List <BeerType> GetAllBeerTypes() { using (var ctx = new BrewAreaEntities()) { return(ctx.BeerTypes.ToList()); } }
public BeerType GetBeerType(int beerTypeId) { using (var ctx = new BrewAreaEntities()) { return(ctx.BeerTypes.Where(t => t.BeerTypeId == beerTypeId).SingleOrDefault()); } }
public int GetGlobalRecipeCountForMember(int memberId) { using (var ctx = new BrewAreaEntities()) { return(ctx.Recipes.Where(t => t.PostedBy == memberId && t.IsActive && t.IsGlobal).Count()); } }
public Member GetById(int id) { using (var ctx = new BrewAreaEntities()) { return(ctx.Members.ToList().SingleOrDefault(t => t.MemberId == id)); } }
public Member GetByUsername(string username) { using (var ctx = new BrewAreaEntities()) { return(ctx.Members.Where(t => t.Username == username).SingleOrDefault()); } }
public Ingredient GetById(int ingredientId) { using (var ctx = new BrewAreaEntities()) { return(ctx.Ingredients.Where(t => t.IngredientId == ingredientId).SingleOrDefault()); } }
public Recipe GetById(int recipeId) { using (var ctx = new BrewAreaEntities()) { return(ctx.Recipes.Where(t => t.RecipeId == recipeId).SingleOrDefault()); } }
public List <Ingredient> GetAll() { using (var ctx = new BrewAreaEntities()) { return(ctx.Ingredients.ToList()); } }
public List <Recipe> GetAllForAdmin() { using (var ctx = new BrewAreaEntities()) { var recipeList = ctx.Recipes.Where(t => t.IsActive).ToList(); return(recipeList); } }
public List <Recipe> GetAllRecipesOfMember(int memberId) { using (var ctx = new BrewAreaEntities()) { var recipeList = ctx.Recipes.Where(t => t.IsActive && t.PostedBy == memberId).ToList(); return(recipeList); } }
public List <Recipe> GetAllPending() { using (var ctx = new BrewAreaEntities()) { var recipeList = ctx.Recipes.Where(t => t.IsActive && !t.IsGlobal).ToList(); return(recipeList); } }
public bool MakeGlobal(int recipeId) { using (var ctx = new BrewAreaEntities()) { var recipe = ctx.Recipes.Where(t => t.RecipeId == recipeId).SingleOrDefault(); if (recipe != null) { recipe.IsGlobal = true; ctx.SaveChanges(); return(true); } return(false); } }
public bool Create(Member member) { using (var ctx = new BrewAreaEntities()) { try { ctx.Members.Add(member); ctx.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public int Create(Recipe newRecipe) { using (var ctx = new BrewAreaEntities()) { try { var newRec = ctx.Recipes.Add(newRecipe); ctx.SaveChanges(); return(newRec.RecipeId); } catch (Exception e) { return(-1); } } }
public bool Create(Ingredient newIngredient) { using (var ctx = new BrewAreaEntities()) { try { ctx.Ingredients.Add(newIngredient); ctx.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public bool EditIngredientToMember(int memberId, int ingredientIdOld, int ingredientId, int measurementTypeId, double amount) { using (var ctx = new BrewAreaEntities()) { try { DeleteIngredientFromMember(memberId, ingredientIdOld); AddIngredientToMember(memberId, ingredientId, measurementTypeId, amount); ctx.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public bool Delete(int id) { using (var ctx = new BrewAreaEntities()) { try { var dbItem = ctx.Recipes.Where(t => t.RecipeId == id).SingleOrDefault(); dbItem.IsActive = false; ctx.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public int CreateByName(string IngredientName) { using (var ctx = new BrewAreaEntities()) { try { var x = ctx.Ingredients.Add(new Ingredient { Name = IngredientName }); ctx.SaveChanges(); return(x.IngredientId); } catch (Exception e) { return(-1); } } }
public int AddMeasurement(string MeasurementType) { using (var ctx = new BrewAreaEntities()) { try { var x = ctx.MeasurementTypes.Add(new MeasurementType { MeasurementType1 = MeasurementType }); ctx.SaveChanges(); return(x.MeasurementTypeId); } catch (Exception e) { return(-1); } } }
public int AddBeerType(string BeerType) { using (var ctx = new BrewAreaEntities()) { try { var x = ctx.BeerTypes.Add(new BeerType { BeerType1 = BeerType }); ctx.SaveChanges(); return(x.BeerTypeId); } catch (Exception e) { return(-1); } } }
public bool Edit(Recipe recipe) { using (var ctx = new BrewAreaEntities()) { try { var driven = ctx.Recipes.Where(t => t.RecipeId == recipe.RecipeId).SingleOrDefault(); driven.Name = recipe.Name; driven.Making = recipe.Making; driven.Description = recipe.Description; driven.BeerTypeId = recipe.BeerTypeId; ctx.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public bool DeleteIngredientFromMember(int memberId, int ingredientId) { using (var ctx = new BrewAreaEntities()) { try { var toDelete = ctx.IngredientMemberRelations.Where(t => t.IngredientId == ingredientId && t.MemberId == memberId).SingleOrDefault(); if (toDelete != null) { ctx.IngredientMemberRelations.Remove(toDelete); ctx.SaveChanges(); } return(true); } catch (Exception e) { return(false); } } }
public IngredientViewModel GetRecipeIngredientById(int recipeId, int ingredientId) { using (var ctx = new BrewAreaEntities()) { try { var rir = ctx.RecipeIngredientRelations.Where(t => t.IngredientId == ingredientId && t.RecipeId == recipeId).SingleOrDefault(); var othRep = new OthersRepo(); return(new IngredientViewModel { Amount = rir.Amount, IngredientName = GetById(ingredientId).Name, MeasurementType = othRep.GetMeasurementType(rir.MeasurementTypeId).MeasurementType1 }); } catch (Exception e) { return(null); } } }
public bool AddIngredientToMember(int memberId, int ingredientId, int measurementTypeId, double amount) { using (var ctx = new BrewAreaEntities()) { try { ctx.IngredientMemberRelations.Add(new IngredientMemberRelation { MemberId = memberId, IngredientId = ingredientId, MeasurementTypeId = measurementTypeId, Amount = amount }); ctx.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
public List <IngredientViewModel> GetMemberIngredients(int memberId) { using (var ctx = new BrewAreaEntities()) { var ribmList = new List <IngredientViewModel>(); var rirList = ctx.IngredientMemberRelations.Where(t => t.MemberId == memberId).ToList(); foreach (var rirItem in rirList) { var ingredientName = ctx.Ingredients.Where(t => t.IngredientId == rirItem.IngredientId).SingleOrDefault().Name; var measurementType = ctx.MeasurementTypes.Where(t => t.MeasurementTypeId == rirItem.MeasurementTypeId).SingleOrDefault().MeasurementType1; var amount = rirItem.Amount; ribmList.Add(new IngredientViewModel { Amount = amount, IngredientName = ingredientName, MeasurementType = measurementType }); } return(ribmList); } }