public bool Save(string guid, string username, int rating) { bool voteSaved; try { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { var newVote = new Vote { Username = username, Rating = rating, RecipeGuid = guid }; context.Votes.InsertOnSubmit(newVote); context.SubmitChanges(); voteSaved = true; } } catch (Exception) { voteSaved = false; } return(voteSaved); }
public bool Create(string userName, string password, string fullName, string emailAddress) { var result = false; try { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { var existingUser = (from u in context.Users where u.Username == userName select u).FirstOrDefault(); if (existingUser == null) { var user = new User { Username = userName, Password = password, FullName = fullName, Email = emailAddress, Role = 1 }; context.Users.InsertOnSubmit(user); context.SubmitChanges(); result = true; } } } catch { LogHandler.Log(nameof(UserRepository), LogType.Error, string.Format("Could not create user {0} with e-mail {1}", userName, emailAddress)); } return(result); }
public void Delete(string guid) { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { var query = context.Votes.FirstOrDefault(x => x.RecipeGuid == guid); if (query != null) { context.Votes.DeleteOnSubmit(query); context.SubmitChanges(); } } }
public bool Save(Recipe recipe) { var result = false; try { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { if (recipe.Id == 0) { var newRecipe = new Recipe { Name = recipe.Name, Ingredients = recipe.Ingredients, Description = recipe.Description, Portions = recipe.Portions, CategoryId = recipe.CategoryId, DishTypeId = recipe.DishTypeId, Date = DateTime.Now, Guid = recipe.Guid }; context.Recipes.InsertOnSubmit(newRecipe); } else { var r = (from c in context.Recipes where c.Id == recipe.Id select c).FirstOrDefault(); r.Name = recipe.Name; r.Ingredients = recipe.Ingredients; r.Description = recipe.Description; r.Portions = recipe.Portions; r.CategoryId = recipe.CategoryId; r.DishTypeId = recipe.DishTypeId; r.Guid = recipe.Guid; r.Id = recipe.Id; } context.SubmitChanges(); result = true; CacheHandler.PurgeCache(); } } catch (Exception ex) { LogHandler.Log(nameof(RecipeRepository), LogType.Error, string.Format("Could not save recipe with name {0}", recipe.Name)); } return(result); }
public bool DeleteVotes(string guid) { var result = false; try { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { var query = context.Votes.FirstOrDefault(x => x.RecipeGuid == guid); if (query != null) { context.Votes.DeleteOnSubmit(query); context.SubmitChanges(); result = true; } } } catch (Exception ex) { LogHandler.Log(nameof(RecipeRepository), LogType.Error, string.Format("Could not delete specials for recipe with GUID {0}", guid)); } return(result); }
public bool Delete(string guid) { var result = false; try { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { var q = context.Recipes.Where(x => x.Guid == guid).ToList().FirstOrDefault(); if (q != null) { context.Recipes.DeleteOnSubmit(q); context.SubmitChanges(); result = true; CacheHandler.PurgeCache(); } } } catch (Exception ex) { LogHandler.Log(nameof(RecipeRepository), LogType.Error, string.Format("Could not delete recipe with GUID {0}", guid)); } return(result); }
public bool SaveSpecial(string guid, int specialId) { var result = false; try { using (var context = new ReceptsamlingenDataContext(ConfigurationManager.ConnectionStrings[ConnectionString].ConnectionString)) { var assign = new SpecialAssign { SpecialId = specialId, RecipeGuid = guid }; context.SpecialAssigns.InsertOnSubmit(assign); context.SubmitChanges(); result = true; } } catch (Exception ex) { LogHandler.Log(nameof(RecipeRepository), LogType.Error, string.Format("Could not save specials for recipe with GUID {0}", guid)); } return(result); }