Exemplo n.º 1
0
        public IActionResult DeleteAddressById(int addressId)
        {
            var email = ClaimsHelper.GetClaim(User, "name");

            _addressService.DeleteAddress(email, addressId);
            return(NoContent());
        }
        public IActionResult ClearCart()
        {
            var email = ClaimsHelper.GetClaim(User, "name");

            _shoppingCartService.ClearCart(email);
            return(NoContent());
        }
Exemplo n.º 3
0
        public IActionResult GetPayments()
        {
            var email        = ClaimsHelper.GetClaim(User, "name");
            var paymentCards = _paymentService.GetStoredPaymentCards(email);

            return(Ok(paymentCards));
        }
        public virtual TEntity Update(TEntity entity)
        {
            if (entity is ITenant)
            {
                (entity as ITenant).TenantId = ClaimsHelper.GetClaim <int>(_http.User, "Tenant");
            }

            var entry = _ctx.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                var keyName = _ctx.Model.FindEntityType(typeof(TEntity)).FindPrimaryKey()
                              .Properties.Select(x => x.Name).Single();
                var id = entity.GetType().GetProperty(keyName).GetValue(entity, null);

                var currentEntity = _ctx.Set <TEntity>().Find(id);
                if (currentEntity != null)
                {
                    var attachedEntry = _ctx.Entry(currentEntity);
                    attachedEntry.CurrentValues.SetValues(entity);
                    attachedEntry.State = EntityState.Modified;
                }
                else
                {
                    _ctx.Set <TEntity>().Attach(entity);
                    entry.State = EntityState.Modified;
                }
            }

            _ctx.SaveChanges();

            return(entity);
        }
        public IActionResult DeleteItemFromCart(int itemId)
        {
            var email = ClaimsHelper.GetClaim(User, "name");

            _shoppingCartService.RemoveCartItem(email, itemId);
            return(NoContent());
        }
Exemplo n.º 6
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var tenantId = ClaimsHelper.GetClaim <int>(_http.User, "Tenant");
            var t        = _tenantHelper.GetTenant(tenantId);
            var constr   = $"server={t.DatabaseServer};database={t.Database};integrated security=true;";

            optionsBuilder.UseSqlServer(constr);
        }
Exemplo n.º 7
0
        public IActionResult AddAddress([FromBody] AddressInputModel address)
        {
            if (!ModelState.IsValid)
            {
                ErrorHandler.GetModelErrors(ModelState);
            }
            var email      = ClaimsHelper.GetClaim(User, "name");
            var newAddress = _addressService.AddAddress(email, address);

            return(CreatedAtRoute("AddAddress", new { id = newAddress.Id }, null));
        }
Exemplo n.º 8
0
        public IActionResult AddPaymentMethod([FromBody] PaymentCardInputModel paymentCard)
        {
            if (!ModelState.IsValid)
            {
                ErrorHandler.GetModelErrors(ModelState);
            }
            var email          = ClaimsHelper.GetClaim(User, "name");
            var newPaymentCard = _paymentService.AddPaymentCard(email, paymentCard);

            return(CreatedAtRoute("AddPaymentMethod", new { id = newPaymentCard.Id }, null));
        }
Exemplo n.º 9
0
        public IActionResult CreateNewOrder([FromBody] OrderInputModel orderModel)
        {
            if (!ModelState.IsValid)
            {
                ErrorHandler.GetModelErrors(ModelState);
            }
            var email    = ClaimsHelper.GetClaim(User, "name");
            var newOrder = _orderService.CreateNewOrder(email, orderModel);

            return(CreatedAtRoute("CreateNewOrder", new { id = newOrder.Id }, null));
        }
        public IActionResult UpdateQuantity([FromBody] UpdateQuantityInputModel cartItem, int itemId)
        {
            if (!ModelState.IsValid)
            {
                ErrorHandler.GetModelErrors(ModelState);
            }
            var email = ClaimsHelper.GetClaim(User, "name");

            _shoppingCartService.UpdateCartItemQuantity(email, itemId, cartItem.Quantity);
            return(Ok());
        }
        public IActionResult AddItemToCart([FromBody] ShoppingCartItemInputModel cartItem)
        {
            if (!ModelState.IsValid)
            {
                ErrorHandler.GetModelErrors(ModelState);
            }

            var email       = ClaimsHelper.GetClaim(User, "name");
            var newCartItem = _shoppingCartService.AddCartItem(email, cartItem);

            return(CreatedAtRoute("AddItemToCart", new { id = newCartItem.Id }, null));
        }
        public virtual IQueryable <TEntity> GetAll()
        {
            var tenantId = ClaimsHelper.GetClaim <int>(_http.User, "Tenant");

            var query = _ctx.Set <TEntity>().AsNoTracking().AsQueryable();

            if (typeof(ITenant).GetTypeInfo().IsAssignableFrom(typeof(TEntity)))
            {
                query = query.Where(i => (i as ITenant).TenantId == tenantId);
            }

            return(query);
        }
Exemplo n.º 13
0
 public IActionResult SignOut()
 {
     int.TryParse(ClaimsHelper.GetClaim(User, "tokenId"), out var tokenId);
     _accountService.Logout(tokenId);
     return(NoContent());
 }
Exemplo n.º 14
0
        public IActionResult GetAllAddresses()
        {
            var email = ClaimsHelper.GetClaim(User, "name");

            return(Ok(_addressService.GetAllAddresses(email)));
        }
        public IActionResult GetAllCartItems()
        {
            var email = ClaimsHelper.GetClaim(User, "name");

            return(Ok(_shoppingCartService.GetCartItems(email)));
        }
Exemplo n.º 16
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");

            modelBuilder.Entity <OrderDetail>(entity =>
            {
                entity.HasKey(e => e.OrderDetailId);

                entity.Property(e => e.OrderDetailId).HasColumnName("OrderDetailID");

                entity.Property(e => e.ItemPrice).HasColumnType("money");

                entity.Property(e => e.LinePrice).HasColumnType("money");

                entity.Property(e => e.OrderId).HasColumnName("OrderID");

                entity.Property(e => e.ProductId).HasColumnName("ProductID");

                entity.HasOne(d => d.Order)
                .WithMany(p => p.OrderDetails)
                .HasForeignKey(d => d.OrderId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_OrderDetails_Orders");

                entity.HasOne(d => d.Product)
                .WithMany(p => p.OrderDetails)
                .HasForeignKey(d => d.ProductId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_OrderDetails_Products");
            });

            modelBuilder.Entity <Order>(entity =>
            {
                entity.HasKey(e => e.OrderId);

                entity.Property(e => e.OrderId).HasColumnName("OrderID");

                entity.Property(e => e.OrderDate).HasColumnType("date");

                entity.Property(e => e.TenantId).HasColumnName("TenantID");
            });

            modelBuilder.Entity <Product>(entity =>
            {
                entity.HasKey(e => e.ProductId);

                entity.Property(e => e.ProductId).HasColumnName("ProductID");

                entity.Property(e => e.Description).IsRequired();

                entity.Property(e => e.ModelNumber)
                .IsRequired()
                .HasMaxLength(50);

                entity.Property(e => e.Name)
                .IsRequired()
                .HasMaxLength(100);

                entity.Property(e => e.Price).HasColumnType("money");
            });

            // Configure entity filter
            modelBuilder.Entity <Order>()
            .HasQueryFilter(o =>
                            EF.Property <int>(o, "TenantId")
                            == ClaimsHelper.GetClaim <int>(_http.User, "Tenant"));

            SetGlobalQueryFilters(modelBuilder);
        }
Exemplo n.º 17
0
        public IActionResult GetAllOrders()
        {
            var email = ClaimsHelper.GetClaim(User, "name");

            return(Ok(_orderService.GetOrders(email)));
        }
Exemplo n.º 18
0
 public void SetGlobalQueryForTenant <T>(ModelBuilder builder) where T : class, ITenant
 {
     builder.Entity <T>()
     .HasQueryFilter(o =>
                     EF.Property <int>(o, "TenantId") == ClaimsHelper.GetClaim <int>(_http.User, "Tenant"));
 }