public async Task <Unit> Handle(DeleteOrderCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Orders.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(User), request.Id);
                }

                _context.Orders.Remove(entity);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
        public async Task <long> Handle(CreateOrderItemCommand request, CancellationToken cancellationToken)
        {
            var entity = new Northland.Net.Domain.OrderItem()
            {
                OrderId   = request.OrderId,
                ProductId = request.ProductId,
                Quantity  = request.Quantity,
                UnitPrice = request.UnitPrice,
                Status    = Status.Activated
            };

            _context.OrderItems.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
示例#3
0
        public async Task <long> Handle(CreateSupplierCommand request, CancellationToken cancellationToken)
        {
            var entity = new Northland.Net.Domain.Supplier()
            {
                CompanyName  = request.CompanyName,
                ContactName  = request.ContactName,
                ContactTitle = request.ContactTitle,
                Phone        = request.Phone,
                Status       = Status.Activated
            };

            _context.Suppliers.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
示例#4
0
        public async Task <long> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            var entity = new Northland.Net.Domain.Order()
            {
                CreateDate  = DateTime.Now,
                OrderDate   = request.OrderDate,
                OrderNumber = request.OrderNumber,
                TotalAmount = request.TotalAmount,
                UserId      = request.UserId,
                Status      = Status.Activated
            };

            _context.Orders.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
            public async Task <Unit> Handle(UpdateOrderCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Orders.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Order), request.Id);
                }

                entity.OrderDate   = request.OrderDate;
                entity.OrderNumber = request.OrderNumber;
                entity.TotalAmount = request.TotalAmount;
                entity.UserId      = request.UserId;

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
示例#6
0
        public async Task <long> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            var entity = new Northland.Net.Domain.User()
            {
                Email    = request.Email,
                ImageUrl = "Default.png",
                Name     = request.Name,
                Surname  = request.Surname,
                Password = request.Password,
                Roles    = Roles.User,
                Status   = Status.Activated
            };

            _context.Users.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
示例#7
0
            public async Task <Unit> Handle(UpdateOrderItemCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.OrderItems.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(OrderItem), request.Id);
                }

                entity.UnitPrice = request.UnitPrice;
                entity.Quantity  = request.Quantity;
                entity.OrderId   = request.OrderId;
                entity.ProductId = request.ProductId;

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(UpdateSupplierCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Suppliers.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Supplier), request.Id);
                }

                entity.CompanyName  = request.CompanyName;
                entity.ContactName  = request.ContactName;
                entity.ContactTitle = request.ContactTitle;
                entity.Phone        = request.Phone;
                entity.LastModified = DateTime.Now;
                entity.Status       = request.Status;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
        public async Task <long> Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            var entity = new Northland.Net.Domain.Product()
            {
                CreateDate     = DateTime.Now,
                ProductName    = request.ProductName,
                ImageUrl       = request.ImageUrl,
                UnitPrice      = request.UnitPrice,
                Package        = request.Package,
                IsDiscontinued = request.IsDiscontinued,
                SupplierId     = request.SupplierId,
                Status         = Status.Activated
            };

            _context.Products.Add(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
示例#10
0
            public async Task <Unit> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Users.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(User), request.Id);
                }

                entity.Name     = request.Name;
                entity.Surname  = request.Surname;
                entity.Email    = request.Email;
                entity.Password = request.Password;
                entity.Roles    = request.Roles;
                entity.ImageUrl = request.ImageUrl;

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
示例#11
0
            public async Task <Unit> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Products.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Product), request.Id);
                }

                entity.ProductName    = request.ProductName;
                entity.UnitPrice      = request.UnitPrice;
                entity.Package        = request.Package;
                entity.ImageUrl       = request.ImageUrl;
                entity.IsDiscontinued = request.IsDiscontinued;
                entity.SupplierId     = request.SupplierId;
                entity.LastModified   = DateTime.Now;
                entity.Status         = request.Status;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }