public Phone Get(int id)
 {
     using (EMobileContext context = new EMobileContext())
     {
         return(context.Phones.Find(id));
     }
 }
 public void Remove(Phone phone)
 {
     using (EMobileContext context = new EMobileContext())
     {
         context.Phones.Remove(phone);
         context.SaveChanges();
     }
 }
 public List <Phone> Find(Expression <Func <Phone, bool> > expression)
 {
     using (EMobileContext context = new EMobileContext())
     {
         var query = context.Phones.Where(expression);
         return(query.ToList());
     }
 }
        public Pagination <Phone> GetPhonesByPage(Int32 pageNumber,
                                                  String name         = null,
                                                  String manufacturer = null,
                                                  Double?priceFrom    = null,
                                                  Double?priceTo      = null,
                                                  Int32 phonesPerPage = 10)
        {
            using (EMobileContext context = new EMobileContext())
            {
                var query = context.Phones.AsQueryable();

                if (!String.IsNullOrEmpty(name) && !String.IsNullOrWhiteSpace(name))
                {
                    query = query.Where(x => x.Name.ToLower().Contains(name.ToLower()));
                }

                if (!String.IsNullOrEmpty(manufacturer) && !String.IsNullOrWhiteSpace(manufacturer))
                {
                    query = query.Where(x => x.Manufacturer.ToLower().Contains(manufacturer.ToLower()));
                }

                if (priceFrom != null)
                {
                    query = query.Where(x => x.Price >= priceFrom);
                }

                if (priceTo != null)
                {
                    query = query.Where(x => x.Price <= priceTo);
                }

                var count = query.Count();

                query = query.OrderBy(x => x.Id)
                        .Skip((pageNumber - 1) * phonesPerPage)
                        .Take(phonesPerPage);

                return(new Pagination <Phone>(query.ToList(), count));
            }
        }
Exemple #5
0
 public static void Seed(this EMobileContext context)
 {
     if (context.Database.EnsureCreated())
     {
         if (context.Mobiles.Any())
         {
             return;
         }
         for (int i = 0; i < 20; i++)
         {
             context.Mobiles.Add(new Mobile()
             {
                 Name             = "Iphone " + new Random().Next(5, 8),
                 CPU              = "A " + new Random().Next(6, 12),
                 OS               = "ios " + new Random().Next(6, 12),
                 Brand            = "Apple",
                 InternalMemory   = "64gb",
                 ScreenResolution = "1140x728",
                 Size             = "128-5-4",
                 ScreenSize       = "5",
                 RAM              = "4gb",
                 Price            = new Random().Next(1500, 2000),
                 VideoUrl         = "https://www.youtube.com/embed/VlefObjJ5hM",
                 Weight           = "128",
                 Photos           = new List <Photo>()
                 {
                     new Photo()
                     {
                         Value = "https://images.kogan.com/image/fetch/s--PYK8gQDP--/b_white,c_pad,f_auto,h_400,q_auto:good,w_600/https://assets.kogan.com/files/product/KHIP6xxxxx/KHIP6xxGLD-webres.jpg"
                     },
                     new Photo()
                     {
                         Value = "https://images.officeworks.com.au/api/2/img/https://s3-ap-southeast-2.amazonaws.com/wc-prod-pim/JPEG_1000x1000/AIP632SG_B_iphone_6_32gb_space_grey_unlocked.jpg/resize?size=706&auth=MjA5OTcwODkwMg__"
                     }
                 }
             });
         }
         context.SaveChanges();
     }
 }
Exemple #6
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="context"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, EMobileContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                c.RoutePrefix = "";
            });
            context.Seed();


            app.UseMvc();
        }
Exemple #7
0
 public BaseRepository(EMobileContext context)
 {
     this._context = context;
 }
Exemple #8
0
 public PhotoRepository(EMobileContext context) : base(context)
 {
 }
Exemple #9
0
 public MobileRepository(EMobileContext context) : base(context)
 {
 }