Ejemplo n.º 1
0
 public List <Category> Categories()
 {
     using (var ctx = new LifeInContext())
     {
         return(ctx.Categories.ToList());
     }
 }
Ejemplo n.º 2
0
 public List <Company> Companies()
 {
     using (var ctx = new LifeInContext())
     {
         return(ctx.Companies.Include("Category").Include("Ratings").Include("Reviews").Include("Tags").Include("Badges").ToList());
     }
 }
Ejemplo n.º 3
0
 public List <Rating> Ratings()
 {
     using (var ctx = new LifeInContext())
     {
         return(ctx.Ratings.ToList());
     }
 }
Ejemplo n.º 4
0
 public List <Badge> ReadAll()
 {
     using (var ctx = new LifeInContext())
     {
         return(ctx.Badges.ToList());
     }
 }
Ejemplo n.º 5
0
 public List <Tag> ReadAll()
 {
     using (var ctx = new LifeInContext())
     {
         return(ctx.Tags.ToList());
     }
 }
Ejemplo n.º 6
0
 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());
     }
 }
Ejemplo n.º 7
0
 public void Add(Company company)
 {
     using (var ctx = new LifeInContext())
     {
         ctx.Companies.Attach(company);
         ctx.Companies.Add(company);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public void Add(Category category)
 {
     using (var ctx = new LifeInContext())
     {
         ctx.Categories.Attach(category);
         ctx.Categories.Add(category);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void Add(Badge item)
 {
     using (var ctx = new LifeInContext())
     {
         ctx.Badges.Attach(item);
         ctx.Badges.Add(item);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 public void Add(Rating item)
 {
     using (var ctx = new LifeInContext())
     {
         ctx.Ratings.Attach(item);
         ctx.Ratings.Add(item);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 12
0
        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();
            }
        }
Ejemplo n.º 13
0
        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();
            }
        }
Ejemplo n.º 14
0
        public void Delete(int id)
        {
            Company company = Find(id);

            using (var ctx = new LifeInContext())
            {
                ctx.Companies.Attach(company);
                ctx.Companies.Remove(company);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 15
0
        public void Delete(int id)
        {
            Rating rating = new Rating();

            using (var ctx = new LifeInContext())
            {
                ctx.Ratings.Attach(rating);
                ctx.Ratings.Remove(rating);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 16
0
        public void Delete(int id)
        {
            Badge Badge = Find(id);

            using (var ctx = new LifeInContext())
            {
                ctx.Badges.Attach(Badge);
                ctx.Badges.Remove(Badge);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 17
0
        public void Delete(int id)
        {
            Category category = Find(id);

            using (var ctx = new LifeInContext())
            {
                ctx.Categories.Attach(category);
                ctx.Categories.Remove(category);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 18
0
        public void Delete(int id)
        {
            Tag tag = Find(id);

            using (var ctx = new LifeInContext())
            {
                ctx.Tags.Attach(tag);
                ctx.Tags.Remove(tag);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 19
0
        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();
            }
        }
Ejemplo n.º 20
0
 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();
     }
 }
Ejemplo n.º 21
0
 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();
         //
     }
 }
Ejemplo n.º 22
0
        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();
            }
        }
Ejemplo n.º 23
0
        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();
            }
        }
Ejemplo n.º 24
0
        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();
            }
        }