public List <Category> Categories() { using (var ctx = new LifeInContext()) { return(ctx.Categories.ToList()); } }
public List <Company> Companies() { using (var ctx = new LifeInContext()) { return(ctx.Companies.Include("Category").Include("Ratings").Include("Reviews").Include("Tags").Include("Badges").ToList()); } }
public List <Rating> Ratings() { using (var ctx = new LifeInContext()) { return(ctx.Ratings.ToList()); } }
public List <Badge> ReadAll() { using (var ctx = new LifeInContext()) { return(ctx.Badges.ToList()); } }
public List <Tag> ReadAll() { using (var ctx = new LifeInContext()) { return(ctx.Tags.ToList()); } }
public List <Company> ReadAll() { using (var ctx = new LifeInContext()) { //ctx.Companies.Include("Rating") return(ctx.Companies.Include("Category").Include(c => c.Ratings).Include("Reviews").Include("Tags").Include("Badges").ToList()); } }
public void Add(Company company) { using (var ctx = new LifeInContext()) { ctx.Companies.Attach(company); ctx.Companies.Add(company); ctx.SaveChanges(); } }
public void Add(Category category) { using (var ctx = new LifeInContext()) { ctx.Categories.Attach(category); ctx.Categories.Add(category); ctx.SaveChanges(); } }
public void Add(Badge item) { using (var ctx = new LifeInContext()) { ctx.Badges.Attach(item); ctx.Badges.Add(item); ctx.SaveChanges(); } }
public void Add(Rating item) { using (var ctx = new LifeInContext()) { ctx.Ratings.Attach(item); ctx.Ratings.Add(item); ctx.SaveChanges(); } }
public void Edit(Category category) { using (var ctx = new LifeInContext()) { var categoryDB = ctx.Companies.FirstOrDefault(x => x.Id == category.Id); categoryDB.Name = category.Name; ctx.SaveChanges(); } }
public void Edit(Badge item) { using (var ctx = new LifeInContext()) { var BadgeDB = ctx.Badges.FirstOrDefault(x => x.Id == item.Id); BadgeDB.Name = item.Name; ctx.SaveChanges(); } }
public void Edit(Tag item) { using (var ctx = new LifeInContext()) { var tagDB = ctx.Tags.FirstOrDefault(x => x.Id == item.Id); tagDB.Name = item.Name; ctx.SaveChanges(); } }
public void Delete(int id) { Company company = Find(id); using (var ctx = new LifeInContext()) { ctx.Companies.Attach(company); ctx.Companies.Remove(company); ctx.SaveChanges(); } }
public void Delete(int id) { Rating rating = new Rating(); using (var ctx = new LifeInContext()) { ctx.Ratings.Attach(rating); ctx.Ratings.Remove(rating); ctx.SaveChanges(); } }
public void Delete(int id) { Badge Badge = Find(id); using (var ctx = new LifeInContext()) { ctx.Badges.Attach(Badge); ctx.Badges.Remove(Badge); ctx.SaveChanges(); } }
public void Delete(int id) { Category category = Find(id); using (var ctx = new LifeInContext()) { ctx.Categories.Attach(category); ctx.Categories.Remove(category); ctx.SaveChanges(); } }
public void Delete(int id) { Tag tag = Find(id); using (var ctx = new LifeInContext()) { ctx.Tags.Attach(tag); ctx.Tags.Remove(tag); ctx.SaveChanges(); } }
public void Edit(Rating item) { using (var ctx = new LifeInContext()) { var ratingDB = ctx.Ratings.FirstOrDefault(x => x.Id == item.Id); ratingDB.OverAll = item.OverAll; ratingDB.Price = item.Price; ratingDB.Quality = item.Quality; ctx.SaveChanges(); } }
public void Add(Company company) { using (var ctx = new LifeInContext()) { ctx.Companies.Add(company); foreach (var item in company.Tags) { ctx.Tags.Remove(ctx.Tags.FirstOrDefault(x => x.Id == item.Id)); ctx.Tags.Attach(ctx.Tags.FirstOrDefault(x => x.Id == item.Id)); } ctx.Entry(company.Category).State = EntityState.Unchanged; ctx.SaveChanges(); } }
public void Add(Company company) { using (var ctx = new LifeInContext()) { // !!!!! GOOOD VERSION DON`T YOU DARE TO CHANGE THIS !!!!!!!!!!! foreach (var item in company.Tags) { ctx.Entry(item).State = EntityState.Unchanged; } ctx.Companies.Add(company); ctx.Entry(company.Category).State = EntityState.Unchanged; ctx.SaveChanges(); // } }
public void Edit(Company company) { using (var ctx = new LifeInContext()) { var companyDB = ctx.Companies. Include("Category"). Include("Tags"). Include("Ratings"). Include("Reviews"). Include("Badges"). FirstOrDefault(x => x.Id == company.Id); ctx.Entry(companyDB).CurrentValues.SetValues(company); companyDB.Tags.Clear(); if (companyDB.Category.Id != company.Category.Id) { companyDB.Category = company.Category; ctx.Entry(company.Category).State = EntityState.Unchanged; } foreach (var item in company.Tags) { companyDB.Tags.Add(ctx.Tags.FirstOrDefault(x => x.Id == item.Id)); } companyDB.Ratings.Clear(); //foreach (var item in company.Ratings) //{ // companyDB.Ratings.Add(ctx.Ratings.FirstOrDefault(x => x.Id == item.Id)); //} for (int i = 0; i < company.Ratings.Count(); ++i) { companyDB.Ratings.Add(company.Ratings.ElementAt(i)); } companyDB.Reviews.Clear(); for (int i = 0; i < company.Reviews.Count(); ++i) { companyDB.Reviews.Add(company.Reviews.ElementAt(i)); } companyDB.Badges.Clear(); foreach (var item in company.Badges) { companyDB.Badges.Add(ctx.Badges.FirstOrDefault(x => x.Id == item.Id)); } companyDB.NrRate = companyDB.Ratings.Count(); ctx.SaveChanges(); } }
public void Edit(Company company) { using (var ctx = new LifeInContext()) { var companyDB = ctx.Companies.FirstOrDefault(x => x.Id == company.Id); companyDB.Name = company.Name; companyDB.ImageUrl = company.ImageUrl; companyDB.Address = company.Address; companyDB.WebSite = company.WebSite; companyDB.Tel = company.Tel; companyDB.OpenHours = company.OpenHours; companyDB.MinPrice = company.MinPrice; companyDB.MaxPrice = company.MaxPrice; companyDB.Description = company.Description; companyDB.NrRate = company.NrRate; companyDB.AvgOvr = company.AvgOvr; companyDB.Category = company.Category; ctx.SaveChanges(); } }
public void Edit(Company company) { using (var ctx = new LifeInContext()) { var companyDB = ctx.Companies. Include("Category"). Include("Tags"). Include("Ratings"). Include("Reviews"). Include("Badges"). FirstOrDefault(x => x.Id == company.Id); ctx.Entry(companyDB).CurrentValues.SetValues(company); companyDB.Tags.Clear(); if (companyDB.Category.Id != company.Category.Id) { companyDB.Category = company.Category; ctx.Entry(company.Category).State = EntityState.Unchanged; } foreach (var item in company.Tags) { companyDB.Tags.Add(ctx.Tags.FirstOrDefault(x => x.Id == item.Id)); } companyDB.Ratings.Clear(); //foreach (var item in company.Ratings) //{ // companyDB.Ratings.Add(ctx.Ratings.FirstOrDefault(x => x.Id == item.Id)); //} for (int i = 0; i < company.Ratings.Count(); ++i) { companyDB.Ratings.Add(company.Ratings.ElementAt(i)); } companyDB.Reviews.Clear(); for (int i = 0; i < company.Reviews.Count(); ++i) { companyDB.Reviews.Add(company.Reviews.ElementAt(i)); } companyDB.Badges.Clear(); foreach (var item in company.Badges) { companyDB.Badges.Add(ctx.Badges.FirstOrDefault(x => x.Id == item.Id)); } //companyDB.CVR = company.CVR; //companyDB.Name = company.Name; //companyDB.ImageUrl = company.ImageUrl; //companyDB.Address = company.Address; //companyDB.WebSite = company.WebSite; //companyDB.Tel = company.Tel; //companyDB.OpenHours = company.OpenHours; //companyDB.MinPrice = company.MinPrice; //companyDB.MaxPrice = company.MaxPrice; //companyDB.Description = company.Description; //companyDB.NrRate = company.NrRate; //companyDB.AvgOvr = company.AvgOvr; //companyDB.Category = company.Category; //companyDB.Ratings = company.Ratings; //companyDB.Tags = company.Tags; //ctx.Entry(company.Category).State = EntityState.Unchanged; //foreach (var item in company.Tags) //{ // ctx.Entry(item).State = EntityState.Unchanged; //} //ctx.Entry(company.Tags).State = EntityState.Unchanged; //companyDB.Ratings = company.Ratings; //foreach (var item in company.Ratings) //{ // ctx.Entry(item).State = EntityState.Unchanged; //} companyDB.NrRate = companyDB.Ratings.Count(); ctx.SaveChanges(); } }