public IQueryable<ItemModel> GetAll(
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(() =>
            {
                var context = new StoreContext();

                var user = context.Users.FirstOrDefault(usr => usr.SessionKey == sessionKey);
                var admin = context.Admins.FirstOrDefault(adm => adm.SessionKey == sessionKey);
                if (user == null && admin == null)
                {
                    throw new InvalidOperationException("Invalid session key!");
                }

                var models = context.Items.Select(ItemModel.FromItem);
                //var models =
                //     from itemEntity in itemEntities
                //     select new ItemModel()
                //     {
                //         ItemId = itemEntity.ItemId,
                //         Name = itemEntity.Name,
                //         Description = itemEntity.Description,
                //         MagicAttack = itemEntity.MagicAttack,
                //         MeleAttack = itemEntity.MeleAttack,
                //         MagicDefense = itemEntity.MagicDefense,
                //         MeleDefense = itemEntity.MeleDefense,
                //         ImageUrl = itemEntity.ImageUrl,
                //         ItemCategory = itemEntity.ItemCategory.Name
                //     };

                return models;
            });

            return responseMsg;
        }
 private void OfflineLicensesChanged(StoreContext sender, object args)
 {
     var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
     {
         await GetLicenseState();
     });
 }
        //GET api/categories/
        public HttpResponseMessage GetAll([ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var categories = context.Categories;
                      var resultCategoryModels = from category in categories
                                                 select new CategoryModel
                                                     {
                                                         Name = category.Name,
                                                         Id = category.Id,
                                                         Description = category.Description,
                                                         ImageSource = category.ImageSource
                                                     }
                                                     ;

                      var response = this.Request.CreateResponse(HttpStatusCode.OK,
                                          resultCategoryModels.ToList());
                      return response;
                  }
              });

            return responseMsg;
        }
        public HttpResponseMessage GetProduct([ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var found = (from product in context.Products.Include("Categories")
                                   select new ProductModel
                                   {
                                       Id = product.Id,
                                       Name = product.Name,
                                       Price = product.Price,
                                       CategoryName = product.Category.Name,
                                       CategoryId = product.Category.Id,
                                       Description = product.Description,
                                       ImageSource = product.ImageSource,
                                       Quantity = product.Quantity
                                   }).ToList();

                      var response = this.Request.CreateResponse(HttpStatusCode.OK,
                                          found);
                      return response;
                  }
              });

            return responseMsg;
        }
        // NOT WORKING because of cascading deletion
        //DELETE api/categories/{categoryId}
        public HttpResponseMessage DeleteCategory(int categoryId, [ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
               () =>
               {
               using (var context = new StoreContext())
               {
                   this.ValidateSessionKey(sessionKey);

                   var admin = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey);
                   if (admin == null)
                   {
                       throw new ArgumentException("Invalid SessionKey or user is already logouted");
                   }
                   else if (admin.IsAdmin != true)
                   {
                       throw new ArgumentException("Unauthorized Access");
                   }

                   var category = context.Categories.FirstOrDefault(c => c.Id == categoryId);
                   if (category == null)
                   {
                       throw new ArgumentException("Category not found");
                   }

                   context.Categories.Remove(category);
                   context.SaveChanges();
                   var response = new HttpResponseMessage(HttpStatusCode.OK);
                   return response;
               }

               });

            return responseMsg;
        }
        public IQueryable<MonsterModel> GetAll(
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(() =>
            {
                var context = new StoreContext();

                var user = context.Users.FirstOrDefault(usr => usr.SessionKey == sessionKey);
                var admin = context.Admins.FirstOrDefault(adm => adm.SessionKey == sessionKey);
                if (user == null && admin == null)
                {
                    throw new InvalidOperationException("Invalid session key!");
                }

                var monsterEntities = context.Monsters;
                var models =
                     from monsterEntity in monsterEntities
                     select new MonsterModel()
                     {
                         MonsterId = monsterEntity.MonsterId,
                         Name = monsterEntity.Name,
                         MeleAttack = monsterEntity.MeleAttack,
                         MagicAttack = monsterEntity.MagicAttack,
                         MagicDefense = monsterEntity.MagicDefense,
                         MeleDefense = monsterEntity.MeleDefense,
                         HP = monsterEntity.HP
                     };

                return models;
            });

            return responseMsg;
        }
        //GET api/products/{productId}
        public HttpResponseMessage GetProduct(int productId, [ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var product = context.Products.Include("Category").FirstOrDefault(p => p.Id == productId);
                      if (product == null)
                      {
                          throw new ArgumentException("Product not found");
                      }

                      var resultProductModel = new ProductModel
                      {
                          Id = product.Id,
                          Name = product.Name,
                          Price = product.Price,
                          CategoryName = product.Category.Name,
                          CategoryId = product.Category.Id,
                          Description = product.Description,
                          ImageSource = product.ImageSource,
                          Quantity = product.Quantity
                      };

                      var response = this.Request.CreateResponse(HttpStatusCode.OK,
                                          resultProductModel);
                      return response;
                  }
              });

            return responseMsg;
        }
Пример #8
0
 public IdentityUnitOfWork(string connectionString)
 {
     db = new StoreContext(connectionString);
     UserManager = new ApplicationUserManager(new UserStore<ApplicationUser>(db));
     RoleManager = new ApplicationRoleManager(new RoleStore<ApplicationRole>(db));
     ClientManager = new ClientManager(db);
 }
        public IQueryable<UserAdminSimpleModel> GetAll(
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var response = this.PerformOperationAndHandleExceptions(() =>
            {
                var context = new StoreContext();

                var admin = context.Admins.FirstOrDefault(a => a.SessionKey == sessionKey);
                if (admin == null)
                {
                    throw new InvalidOperationException("Invalid session key");
                }

                var users =
                    from u in context.Users
                    select new UserAdminSimpleModel
                    {
                        UserId = u.UserId,
                        Username = u.Username
                    };

                return users;
            });

            return response;
        }
Пример #10
0
        EAuthor EAuthor(StoreContext context, string name)
        {
            var eAuthor = context.Authors.FirstOrDefault(a => a.Name == name);
            if (eAuthor != null)
                return eAuthor;

            eAuthor = new EAuthor { Name = name };
            return eAuthor;
        }
Пример #11
0
        EBook EBook(StoreContext context, Book book)
        {
            var eBook = EBooks.FirstOrDefault(b => b.Id == book.Id);
            if (eBook != null)
                return eBook;

            eBook = new EBook { RegisteredAt = Clock.GetTime() };
            context.Books.Add(eBook);
            return eBook;
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_context != null)
         {
             _context.Dispose();
             _context = null;
         }
     }
 }
Пример #13
0
 static void ClearDB()
 {
     using (var db = new StoreContext())
     {
         db.Sales.RemoveRange(db.Sales);
         db.Goods.RemoveRange(db.Goods);
         db.Clients.RemoveRange(db.Clients);
         db.Managers.RemoveRange(db.Managers);
         db.SaveChanges();
     }
 }
Пример #14
0
        private void AddBindings()
        {
            //TODO: try without arg
            //kernel.Bind<IColorLogic>()
            //    .To<ColorLogic>()
            //    .WithConstructorArgument("repository", new ColorRepository(context));

            //kernel.Bind<DbContext>().To<StoreContext>().InSingletonScope();
            //kernel.Bind<DbContext>().To<StoreContext>().

            //kernel.Bind<IGoodLogic>()
            //   .To<GoodLogic>()
            //   .WithConstructorArgument("repository", new ColorRepository(context));

            //ninject constructor injection

            var context = new StoreContext();

            kernel.Bind<IRepository<Color>>().To<ColorRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IRepository<Good>>().To<GoodRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IRepository<Category>>().To<CategoryRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            //kernel.Bind<IRepository<OrderItem>>().To<OrderItemRepository>()
            //    .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IOrderItemRepository>().To<OrderItemRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IRepository<Order>>().To<OrderRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IRepository<Status>>().To<StatusRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IClientRepository>().To<ClientRepository>()
                .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IGoodRepository>().To<GoodRepository>()
             .WithConstructorArgument("storeContext", StoreContext.StoreContextInstance);

            kernel.Bind<IGoodLogic>().To<GoodLogic>();
            kernel.Bind<IColorLogic>().To<ColorLogic>();
            kernel.Bind<ICategoryLogic>().To<CategoryLogic>();
            kernel.Bind<IOrderItemLogic>().To<OrderItemLogic>();
            kernel.Bind<IOrderLogic>().To<OrderLogic>();
            kernel.Bind<IStatusLogic>().To<StatusLogic>();
            kernel.Bind<IClientLogic>().To<ClientLogic>();
        }
        //GET api/orders/
        public HttpResponseMessage GetAll([ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var admin = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey);
                      if (admin == null)
                      {
                          throw new ArgumentException("Invalid SessionKey or user is already logouted");
                      }
                      else if (admin.IsAdmin != true)
                      {
                          throw new ArgumentException("Unauthorized Access");
                      }

                      var orders = context.Orders;
                      var resultOrdersModel = from order in orders
                                              select new OrderModel
                      {
                          Id = order.Id,
                          UserId = order.User.Id,
                          Username = order.User.Username,
                          SingleOrders = from singleOrder in order.SingleOrders
                                         select new SingleOrderModel
                                     {
                                         Id = singleOrder.Id,
                                         Quantity = singleOrder.Quantity,
                                         Product = new ProductModel
                                         {
                                             Id = singleOrder.Product.Id,
                                             Name = singleOrder.Product.Name,
                                             Description = singleOrder.Product.Description,
                                             ImageSource = singleOrder.Product.ImageSource,
                                             CategoryId = singleOrder.Product.Category.Id,
                                             CategoryName = singleOrder.Product.Category.Name,
                                             Price = singleOrder.Product.Price
                                         }
                                     }
                      };

                      var response = this.Request.CreateResponse(HttpStatusCode.OK,
                                          resultOrdersModel.ToList());
                      return response;
                  }
              });

            return responseMsg;
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            storeContext = StoreContext.GetDefault();
            storeContext.OfflineLicensesChanged += OfflineLicensesChanged;

            StoreProductResult result = await storeContext.GetStoreProductForCurrentAppAsync();
            if (result.ExtendedError == null)
            {
                PurchasePrice.Text = result.Product.Price.FormattedPrice;
            }

            await GetLicenseState();
        }
        public HttpResponseMessage PostCreateMonster(
            MonsterModel model,
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
                () =>
                {
                    if (model.Name == null)
                    {
                        throw new ArgumentNullException("name", "The name cannot be null!");
                    }

                    var context = new StoreContext();
                    using (context)
                    {
                        var admin = context.Admins.FirstOrDefault(adm => adm.SessionKey == sessionKey);
                        if (admin == null)
                        {
                            throw new InvalidOperationException("You are not admin!");
                        }

                        var monster = new Monster()
                        {
                            Name = model.Name,
                            MeleAttack = model.MeleAttack,
                            MagicAttack = model.MagicAttack,
                            MagicDefense = model.MagicDefense,
                            MeleDefense = model.MeleDefense,
                            HP = model.HP
                        };

                        context.Monsters.Add(monster);
                        context.SaveChanges();

                        var createdMonsterModel = new CreatedMonsterModel()
                        {
                            Monsterid = monster.MonsterId,
                            Name = monster.Name
                        };

                        var response =
                            this.Request.CreateResponse(HttpStatusCode.Created, createdMonsterModel);
                        return response;
                    }
                });

            return responseMsg;
        }
Пример #18
0
        public int Write(Book book)
        {
            var context = new StoreContext();
            var eBook = EBook(context, book);

            if (eBook.Id != 0 && eBook.Price != book.Price)
                new PriceChanged(eBook.Id, eBook.Price, book.Price).Implement();

            eBook.Isbn = book.Isbn;
            eBook.Title = book.Title;
            eBook.PublishedAt = book.PublishedAt;
            eBook.Price = book.Price;
            eBook.Authors.Replace(book.Authors.Select(a => EAuthor(context, a)));

            context.SaveChanges();
            return eBook.Id;
        }
        public UserAdminModel GetUserById(int id, [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var response = this.PerformOperationAndHandleExceptions(() =>
            {
                var context = new StoreContext();

                var admin = context.Admins.FirstOrDefault(a => a.SessionKey == sessionKey);
                if (admin == null)
                {
                    throw new InvalidOperationException("Invalid session key");
                }
                var fromUser = UserAdminModel.FromUser;
                var user = context.Users.Select(fromUser);
                return user.FirstOrDefault(u => u.UserId == id);
            });

            return response;
        }
Пример #20
0
    public static void SaveReportToMongoDB()
    {
        if (!mongoDB.CollectionExists("ProductReports"))
        {
            mongoDB.CreateCollection("ProductReports");
        }

        MongoCollection productReports = mongoDB.GetCollection("ProductReports");
        productReports.RemoveAll();

        StoreContext db = new StoreContext();
        var queryProducts =
                                 from vendors in db.Vendors
                                 join products in db.Products
                                 on vendors.ID equals products.VendorID
                                 join sales in db.Sales
                                 on products.ID equals sales.ProductID
                                 select new
                                 {
                                     ProductId = products.ID,
                                     PriductName = products.ProductName,
                                     VendorName = vendors.VendorName,
                                     Quantity = sales.Quantity,
                                     Income = sales.Sum
                                 };

        var goupedProducts = from products in queryProducts
                             group products by products.ProductId into p
                             select new
                             {
                                 ProductId = p.Select(a => a.ProductId).FirstOrDefault(),
                                 ProductName = p.Select(a => a.PriductName).FirstOrDefault(),
                                 VendorName = p.Select(a => a.VendorName).FirstOrDefault(),
                                 TotalQuantitySold = p.Sum(a => a.Quantity),
                                 TotalIncomes = p.Sum(a => a.Income)
                             };
        foreach (var prod in goupedProducts)
        {
            var bson = prod.ToBsonDocument();
            productReports.Insert(bson);
        }
    }
        public HttpResponseMessage GetById(int id, 
            [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey)
        {
            var response = this.PerformOperationAndHandleExceptions(() =>
            {
                var context = new StoreContext();

                var user = context.Users.FirstOrDefault(usr => usr.SessionKey == sessionKey);
                if (user == null)
                {
                    throw new InvalidOperationException("Invalid session key");
                }

                var hero = context.Heros.Where(h => h.HeroId == id).Select(HeroModel.FromHero);

                var responseMsg = this.Request.CreateResponse(HttpStatusCode.OK, hero);
                return responseMsg;
            });

            return response;
        }
Пример #22
0
        public HttpResponseMessage PostLoginUser([FromBody]UserModel model)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
              () =>
              {
                  var context = new StoreContext();
                  using (context)
                  {
                      this.ValidateUsername(model.username);
                      this.ValidateAuthCode(model.authCode);
                      var usernameToLower = model.username.ToLower();
                      var user = context.Users.FirstOrDefault(
                          usr => usr.Username == usernameToLower
                          && usr.AuthCode == model.authCode);

                      if (user == null)
                      {
                          throw new InvalidOperationException("Invalid username or password");
                      }
                      if (user.SessionKey == null)
                      {
                          user.SessionKey = this.GenerateSessionKey(user.Id);
                          context.SaveChanges();
                      }

                      var loggedModel = new LoggedUserModel()
                      {
                          SessionKey = user.SessionKey
                      };

                      var response =
                          this.Request.CreateResponse(HttpStatusCode.Created,
                                          loggedModel);
                      return response;
                  }
              });

            return responseMsg;
        }
        public HttpResponseMessage PostLoginAdmin(UserLoginModel model)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(
              () =>
              {
                  var context = new StoreContext();
                  using (context)
                  {
                      this.ValidateUsername(model.Username);
                      this.ValidateAuthCode(model.AuthCode);
                      var usernameToLower = model.Username.ToLower();
                      var admin = context.Admins.FirstOrDefault(
                          adm => adm.Username == usernameToLower
                          && adm.AuthCode == model.AuthCode);

                      if (admin == null)
                      {
                          throw new InvalidOperationException("Invalid username or password");
                      }

                      if (admin.SessionKey == null)
                      {
                          admin.SessionKey = this.GenerateSessionKey(admin.AdminId);
                          context.SaveChanges();
                      }

                      var loggedModel = new LoggedUserModel()
                      {
                          DisplayName = admin.DisplayName,
                          SessionKey = admin.SessionKey
                      };

                      var response = this.Request.CreateResponse(HttpStatusCode.Created, loggedModel);
                      return response;
                  }
              });

            return responseMsg;
        }
        /*
        {
          "username": "******",
          "nickname": "Doncho Minkov",
          "authCode":   "b1cee3eb7599a7efb89a6e5fb3c9efb133d0a33e"
        }
           */
        //GET api/users
        public HttpResponseMessage GetAll([ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var admin = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey);
                      if (admin == null)
                      {
                          throw new ArgumentException("Invalid SessionKey or user is already logouted");
                      }
                      else if (admin.IsAdmin != true)
                      {
                          throw new ArgumentException("Unauthorized Access");
                      }

                      var users = context.Users;

                      var userModels = from model in users
                                       select new UserModel {
                                            DisplayName = model.DisplayName,
                                            Username = model.Username,
                                            IsAdmin = model.IsAdmin,
                                            ImageSource = model.ImageSource
                                       };
                      var resultUserModels = userModels.ToList();
                      var response =
                          this.Request.CreateResponse(HttpStatusCode.OK,
                                          resultUserModels);
                      return response;
                  }
              });

            return responseMsg;
        }
 public CountryRepository(StoreContext storeContext) : base(storeContext)
 {
 }
Пример #26
0
 public Repository(StoreContext storeContext)
 {
     db = storeContext;
 }
 private Culture GetCorrespondingCulture(StoreContext storeContext)
 {
     return storeContext.AvailableCultures.FirstOrDefault(ac => ac.NetName.EqualsInvariantCultureIgnoreCase(this._orchardServices.WorkContext.CurrentCulture));
 }
 public IndexModel(ILogger <IndexModel> logger, StoreContext context, UserManager <WebUser> userManager)
 {
     _logger      = logger;
     _context     = context;
     _userManager = userManager;
 }
Пример #29
0
 public GenericRepository(StoreContext context)
 {
     _context = context;
 }
Пример #30
0
 public StoreService(StoreContext context)
 {
     _db = context;
 }
Пример #31
0
 public QueryHandler(StoreContext storeContext)
 {
     _storeContext = storeContext;
 }
Пример #32
0
 public BuggyController(StoreContext context)
 {
     _context = context;
 }
        //PUT api/products/{productId}
        public HttpResponseMessage PutProduct([FromBody]ProductModel model, int productId, [ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var admin = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey);
                      if (admin == null)
                      {
                          throw new ArgumentException("Invalid SessionKey or user is already logouted");
                      }
                      else if (admin.IsAdmin != true)
                      {
                          throw new ArgumentException("Unauthorized Access");
                      }

                      //TODO: Validate Escaping

                      var existingProduct = context.Products.FirstOrDefault(p => p.Id == productId);

                      if (existingProduct == null)
                      {
                          throw new ArgumentException("Product not found");
                      }

                      var category = context.Categories.FirstOrDefault(c => c.Id == model.CategoryId);

                      if (category == null)
                      {
                          throw new ArgumentException("Category not found");
                      }

                      if (model.Name != null)
                      {
                          existingProduct.Name = model.Name;
                      }

                      if (model.Description != null)
                      {
                          existingProduct.Description = model.Description;
                      }

                      existingProduct.Category = category;

                      if (model.Price != 0)
                      {
                          existingProduct.Price = model.Price;
                      }

                      //TODO: Should have an option to set the quantity 0
                      //default quantity-to is 1 = 0;
                      if (model.Quantity != 0)
                      {
                          existingProduct.Quantity = model.Quantity;
                      }
                      var product = new Product
                      {
                          Name = model.Name,
                          Description = model.Description,
                          ImageSource = model.ImageSource,
                          Category = category,
                          Price = model.Price,
                          Quantity = model.Quantity,
                      };

                      context.SaveChanges();
                  }

                  var response = new HttpResponseMessage(HttpStatusCode.Created);
                  return response;
              });

            return responseMsg;
        }
Пример #34
0
 public OrderRepository(StoreContext context)
 {
     _context = context;
 }
 public ProductRepository(StoreContext context)
 {
     _context = context;
 }
Пример #36
0
 public CategoryTests()
 {
     _db = new StoreContextFactory().CreateDbContext(new string[0]);
     CleanDatabase();
 }
Пример #37
0
 public ProductsController(StoreContext storeContext)
 {
     _storeContext = storeContext;
 }
 //isesion
 public CompareManager(ISessionManager session, StoreContext db)
 {
     this.session = session;
     this.db      = db;
 }
Пример #39
0
 public OrderDetailRepo(StoreContext context) : base(context)
 {
 }
Пример #40
0
 public GoodRepository(StoreContext storeContext)
     : base(storeContext)
 {
 }
Пример #41
0
 public CategoryRepo(StoreContext context) : base(context)
 {
 }
Пример #42
0
 public CategoryTests()
 {
     _db = new StoreContext();
     CleanDatabase();
 }
Пример #43
0
 public OrderRepo(
     StoreContext context) : base(context)
 {
 }
        //POST api/products
        public HttpResponseMessage PostProduct([FromBody]ProductModel model, [ValueProvider(typeof(HeaderValueProviderFactory<string>))]string sessionKey)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions<HttpResponseMessage>(
              () =>
              {
                  using (var context = new StoreContext())
                  {
                      this.ValidateSessionKey(sessionKey);

                      var admin = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey);
                      if (admin == null)
                      {
                          throw new ArgumentException("Invalid SessionKey or user is already logouted");
                      }
                      else if (admin.IsAdmin != true)
                      {
                          throw new ArgumentException("Unauthorized Access");
                      }

                      //TODO: Validate Escaping

                      var category = context.Categories.Find(model.CategoryId);

                      if (category == null)
                      {
                          throw new ArgumentException("Category not found");
                      }

                      var product = new Product
                      {
                          Name = this.EscapeChars(model.Name),
                          Description = this.EscapeChars(model.Description),
                          ImageSource = this.EscapeChars(model.ImageSource),
                          Category = category,
                          Price = model.Price,
                          Quantity = model.Quantity,
                      };

                      context.Products.Add(product);
                      context.SaveChanges();
                  }

                  var response = new HttpResponseMessage(HttpStatusCode.Created);
                  return response;
              });

            return responseMsg;
        }
Пример #45
0
 public CustomerRepository(StoreContext context)
     : base(context)
 {
 }
Пример #46
0
 public AgentPlusUsersController(StoreContext context)
 {
     _context = context;
 }
Пример #47
0
    private void CalculateShippingCost(
        ShippingOption shippingOption,
        out decimal shippingCost,
        out decimal handlingFee)
    {
        OrderCalculator orderCalculator = new OrderCalculator();

        ShippingMethod shippingMethod = shippingOption.CreateNonRealTimeShippingMethod();

        if (StoreContext.CheckoutDetails.Coupon.DiscountType == Vevo.Domain.Discounts.Coupon.DiscountTypeEnum.FreeShipping)
        {
            shippingCost = 0;
        }
        else
        {
            decimal shippingCostProduct = orderCalculator.GetShippingCost(
                shippingMethod,
                StoreContext.ShoppingCart.SeparateCartItemGroups(),
                StoreContext.WholesaleStatus,
                StoreContext.GetOrderAmount().Discount);
            decimal shippingCostPromotion = CartItemPromotion.GetShippingCostFromPromotion(shippingMethod,
                                                                                           StoreContext.ShoppingCart.SeparateCartItemGroups(),
                                                                                           StoreContext.WholesaleStatus,
                                                                                           StoreContext.GetOrderAmount().Discount);
            if (shippingMethod.GetType().IsAssignableFrom(typeof(FixedShippingMethod)))
            {
                if (shippingCostProduct > shippingCostPromotion)
                {
                    shippingCost = shippingCostProduct;
                }
                else
                {
                    shippingCost = shippingCostPromotion;
                }
            }
            else
            {
                shippingCost = shippingCostProduct + shippingCostPromotion;
            }
        }


        handlingFee = orderCalculator.GetHandlingFee(
            shippingMethod,
            StoreContext.ShoppingCart.SeparateCartItemGroups(),
            StoreContext.WholesaleStatus);
    }