Exemplo n.º 1
0
 public IList <HopForm> GetHopForms()
 {
     using (var context = new MicrobrewitContext())
     {
         return(context.HopForms.ToList());
     }
 }
 public void Add(Brewery brewery)
 {
     using (var context = new MicrobrewitContext())
     {
         brewery.Origin               = null;
         brewery.CreatedDate          = DateTime.Now;
         brewery.UpdatedDate          = DateTime.Now;
         context.Entry(brewery).State = EntityState.Added;
         try
         {
             context.SaveChanges();
         }
         catch (DbEntityValidationException dbEx)
         {
             foreach (var validationErrors in dbEx.EntityValidationErrors)
             {
                 foreach (var validationError in validationErrors.ValidationErrors)
                 {
                     Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                     Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public HopForm GetForm(int id)
 {
     using (var context = new MicrobrewitContext())
     {
         return(context.HopForms.SingleOrDefault(h => h.Id == id));
     }
 }
Exemplo n.º 4
0
        protected override int?ResolveCore(FermentableDto source)
        {
            using (var context = new MicrobrewitContext())
            {
                Supplier supplier = null;
                if (source.Supplier != null)
                {
                    supplier = context.Suppliers.SingleOrDefault(s => s.SupplierId == source.Supplier.Id || s.Name.Equals(source.Supplier.Name));

                    if (supplier == null)
                    {
                        supplier = new Supplier()
                        {
                            Name = source.Supplier.Name,
                        };
                        context.Suppliers.Add(supplier);
                        context.SaveChanges();
                    }
                    return(supplier.SupplierId);
                }
                else
                {
                    return(null);
                }
            }
        }
 public IList <BrewerySocial> GetBrewerySocials(int breweryId)
 {
     using (var context = new MicrobrewitContext())
     {
         return(context.BrewerySocials.Where(b => b.BreweryId == breweryId).ToList());
     }
 }
Exemplo n.º 6
0
 public override async Task <int> UpdateAsync(params User[] users)
 {
     using (var context = new MicrobrewitContext())
     {
         foreach (var user in users)
         {
             var originalUser = context.Users.SingleOrDefault(u => u.Username == user.Username);
             if (originalUser != null)
             {
                 SetChanges(context, originalUser, user);
                 foreach (var social in user.Socials)
                 {
                     var originalSocial =
                         context.UserSocials.SingleOrDefault(
                             s => s.Username == user.Username && s.SocialId == social.SocialId);
                     if (originalSocial != null)
                     {
                         SetChanges(context, originalSocial, social);
                     }
                     else
                     {
                         context.UserSocials.Add(social);
                     }
                 }
             }
         }
         return(await context.SaveChangesAsync());
     }
 }
 public async Task <IList <BreweryMember> > GetAllMembersAsync(int breweryId)
 {
     using (var context = new MicrobrewitContext())
     {
         return(await context.BreweryMembers.Where(b => b.BreweryId == breweryId).ToListAsync());
     }
 }
 public async Task <BreweryMember> GetSingleMemberAsync(int breweryId, string username)
 {
     using (var context = new MicrobrewitContext())
     {
         return(await context.BreweryMembers.SingleOrDefaultAsync(bm => bm.MemberUsername.Equals(username) && bm.BreweryId == breweryId));
     }
 }
Exemplo n.º 9
0
 public async Task <IList <HopForm> > GetHopFormsAsync()
 {
     using (var context = new MicrobrewitContext())
     {
         return(await context.HopForms.ToListAsync());
     }
 }
Exemplo n.º 10
0
 public void Add(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         if (fermentable.Supplier != null)
         {
             fermentable.Supplier = null;
         }
         context.Entry(fermentable).State = EntityState.Added;
         try
         {
             context.SaveChanges();
         }
         catch (DbEntityValidationException dbEx)
         {
             foreach (var validationErrors in dbEx.EntityValidationErrors)
             {
                 foreach (var validationError in validationErrors.ValidationErrors)
                 {
                     Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                            validationError.ErrorMessage);
                     Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName,
                                     validationError.ErrorMessage);
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
 public virtual async Task AddAsync(Other origin)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(origin).State = EntityState.Added;
         try
         {
             await context.SaveChangesAsync();
         }
         catch (DbEntityValidationException dbEx)
         {
             //foreach (var validationErrors in dbEx.EntityValidationErrors)
             //{
             //    foreach (var validationError in validationErrors.ValidationErrors)
             //    {
             //        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             //        Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             //        throw dbEx;
             //    }
             //}
             throw;
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
Exemplo n.º 12
0
 protected override IList <Hop> ResolveCore(HopDto dto)
 {
     using (var context = new MicrobrewitContext())
     {
         List <Hop> hops = new List <Hop>();
         if (dto.Substituts != null)
         {
             foreach (var sub in dto.Substituts)
             {
                 if (sub.Id > 0)
                 {
                     var hop = context.Hops.SingleOrDefault(h => h.HopId == sub.Id);
                     if (hop != null)
                     {
                         hops.Add(hop);
                     }
                 }
                 else
                 {
                     var hop = context.Hops.SingleOrDefault(h => h.Name.Equals(sub.Name));
                     if (hop != null)
                     {
                         hops.Add(hop);
                     }
                 }
             }
         }
         return(hops);
     }
 }
        public virtual void Add(params T[] items)
        {
            using (var context = new MicrobrewitContext())
            {
                foreach (T item in items)
                {
                    context.Entry(item).State = EntityState.Added;
                }

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                            Log.DebugFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public async Task <bool> ConfirmBreweryMemberAsync(string username, NotificationDto notificationDto)
        {
            using (var context = new MicrobrewitContext())
            {
                var breweryMember = await
                                    context.BreweryMembers.SingleOrDefaultAsync(
                    b => b.BreweryId == notificationDto.Id && b.MemberUsername == username);

                if (breweryMember == null)
                {
                    return(false);
                }
                if (notificationDto.Value)
                {
                    breweryMember.Confirmed = true;
                }
                else
                {
                    context.BreweryMembers.Remove(breweryMember);
                }
                await context.SaveChangesAsync();

                return(true);
            }
        }
Exemplo n.º 15
0
 protected override int ResolveCore(T source)
 {
     using (var context = new MicrobrewitContext())
     {
         return(1);
     }
 }
Exemplo n.º 16
0
 public IEnumerable <UserSocial> GetUserSocials(string username)
 {
     using (var context = new MicrobrewitContext())
     {
         return(context.UserSocials.Where(s => s.Username == username).ToList());
     }
 }
Exemplo n.º 17
0
 public async Task <IEnumerable <UserBeer> > GetAllUserBeersAsync(string username)
 {
     using (var context = new MicrobrewitContext())
     {
         return(await context.UserBeers.Where(u => u.Username == username).ToListAsync());
     }
 }
Exemplo n.º 18
0
 public IList <BreweryMember> GetMembers(int breweryId)
 {
     using (var context = new MicrobrewitContext())
     {
         return(context.BreweryMembers.Where(bm => bm.BreweryId == breweryId).ToList());
     }
 }
Exemplo n.º 19
0
 public IList <BreweryMember> GetMemberships(string username)
 {
     using (var context = new MicrobrewitContext())
     {
         return(context.BreweryMembers.Where(b => b.MemberUsername.Equals(username)).ToList());
     }
 }
Exemplo n.º 20
0
 public static void InsertDataDatabase()
 {
     using (var context = new MicrobrewitContext())
     {
         var insert = File.ReadAllText(@"..\..\JSON\insert.sql");
         context.Database.ExecuteSqlCommand(insert);
     }
 }
Exemplo n.º 21
0
 public virtual void Update(Fermentable fermentable)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(fermentable).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 22
0
 public virtual void Remove(BeerStyle beerStyle)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(beerStyle).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 23
0
 public async Task AddMemberAsync(BreweryMember breweryMember)
 {
     using (var context = new MicrobrewitContext())
     {
         context.BreweryMembers.Add(breweryMember);
         await context.SaveChangesAsync();
     }
 }
Exemplo n.º 24
0
 public async Task UpdateMemberAsync(BreweryMember breweryMember)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(breweryMember).State = EntityState.Modified;
         await context.SaveChangesAsync();
     }
 }
Exemplo n.º 25
0
 public async Task AddAsync(Beer beer)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(beer).State = EntityState.Added;
         await context.SaveChangesAsync();
     }
 }
Exemplo n.º 26
0
 public static void DeleteDataInDatabase()
 {
     using (var context = new MicrobrewitContext())
     {
         var delete = File.ReadAllText(@"..\..\JSON\delete.sql");
         context.Database.ExecuteSqlCommand(delete);
     }
 }
Exemplo n.º 27
0
 public virtual void Remove(Other other)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(other).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 28
0
 public virtual void Update(Other other)
 {
     using (var context = new MicrobrewitContext())
     {
         context.Entry(other).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 29
0
 public async Task <IList <Hop> > GetAllAsync(params string[] navigationProperties)
 {
     using (var context = new MicrobrewitContext())
     {
         IQueryable <Hop> dbQueryable = context.Set <Hop>();
         dbQueryable = navigationProperties.Aggregate(dbQueryable, (current, navigationProperty) => current.Include(navigationProperty));
         return(await dbQueryable.ToListAsync());
     }
 }
Exemplo n.º 30
0
 public async Task <Hop> GetSingleAsync(int id, params string[] navigtionProperties)
 {
     using (var context = new MicrobrewitContext())
     {
         IQueryable <Hop> dbQueryable = context.Set <Hop>();
         dbQueryable = navigtionProperties.Aggregate(dbQueryable, (current, navigationProperty) => current.Include(navigationProperty));
         return(await dbQueryable.SingleOrDefaultAsync(h => h.HopId == id));
     }
 }