public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var totalAmount = OrderItems.Sum(item => item.Price * item.Quantity);

            var orderItems = OrderItems.Select(items => new OrderItem(items.ProductId,
                                                                      items.Quantity,
                                                                      items.Price * items.Quantity,
                                                                      PaymentMethod));

            var paymentDetails = new PaymentDetails(CashAmount,
                                                    CardNumber,
                                                    CardOwner,
                                                    totalAmount,
                                                    PaymentMethod);

            var paymentFactory = PaymentFactory.Create(paymentDetails);
            var paymentResult  = paymentFactory.Pay(paymentDetails);

            if (!paymentResult.IsSuccess)
            {
                return(await FailAsync(ErrorCode.PaymentUnsuccesfull));
            }

            var order = new Domain.OrderManagement.Order(BoothId,
                                                         totalAmount,
                                                         OrderStatus.Placed,
                                                         orderItems.ToList());

            await SaveAsync(order, _orderRepository);

            return(await OkAsync(DomainOperationResult.CreateEmpty()));
        }
示例#2
0
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            try
            {
                var product = await _productRepository.GetByIdAsync(Id);

                var categoryIds = _db.Set <Category>()
                                  .Where(category => CategoryIds.Contains(category.Id))
                                  .Select(category => category.Id)
                                  .Distinct()
                                  .ToList();

                var photo = new Photo(PhotoUrl,
                                      PhotoWidth,
                                      PhotoHeight);

                product.ChangeDetails(Name,
                                      Amount,
                                      Code,
                                      categoryIds?.Any() == true ? string.Join(',', categoryIds) : string.Empty,
                                      photo);

                await SaveAsync(product, _productRepository);

                return(await OkAsync(DomainOperationResult.Create(product.Id)));
            }
            catch (System.Exception)
            {
                return(await FailAsync(ErrorCode.Exception));
            }
        }
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var booth = await _boothRepository.GetByIdAsync(BoothId);

            if (booth == null)
            {
                return(await FailAsync(ErrorCode.NotFound));
            }

            var salary = new Salary(Salary);

            var phone = new Phone(PhoneNumber);

            var boothStaff = new Domain.BoothManagement.BoothStaff(FirstName,
                                                                   LastName,
                                                                   salary,
                                                                   phone);

            await _db.Set <Domain.BoothManagement.BoothStaff>()
            .AddAsync(boothStaff);

            await _db.SaveChangesAsync();

            return(await OkAsync(DomainOperationResult.Create(boothStaff.Id)));
        }
示例#4
0
        public override CommandExecutionResult Execute()
        {
            var order = _db.Set <Order>().Find(Id);

            order.Cancel();
            _unitOfWork.Save();
            return(Ok(DomainOperationResult.Create(Id)));
        }
        public override CommandExecutionResult Execute()
        {
            var evnt  = _db.Set <Domain.Event.Event>().Find(EventId);
            var order = new Order(Email, TicketCount, EventId, evnt.Name);

            evnt.PlaceOrder(TicketCount);
            _db.Set <Order>().Add(order);
            _unitOfWork.Save();
            return(Ok(DomainOperationResult.Create(order.Id)));
        }
示例#6
0
        protected CommandExecutionResult Ok(DomainOperationResult data)
        {
            var result = new CommandExecutionResult
            {
                Data    = data,
                Success = true
            };

            return(result);
        }
示例#7
0
        public override CommandExecutionResult Execute()
        {
            var @event = new Event(EventName, EventDate, new Venue(VenueName, Longitude, Latitude), SeatCount, Poster, VideoUrl, Description);

            _db.Set <Event>().Add(@event);

            _unitOfWork.Save();

            return(Ok(DomainOperationResult.CreateEmpty()));
        }
示例#8
0
        void IVariable <int> .Remove(int value, out DomainOperationResult result)
        {
            if (((IVariable <int>) this).Instantiated() || value > this.Domain.UpperBound || value < this.Domain.LowerBound)
            {
                result = DomainOperationResult.ElementNotInDomain;
                return;
            }

            ((IVariable <int>) this).Remove(value, this.State.Depth, out result);
        }
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var address = new Address(Street,
                                      City);

            var booth = new Domain.BoothManagement.Booth(Code,
                                                         address);

            await SaveAsync(booth, _boothRepository);

            return(await OkAsync(DomainOperationResult.Create(booth.Id)));
        }
示例#10
0
        void IDomain <int> .Instantiate(int value, out DomainOperationResult result)
        {
            if (!IsInDomain(value))
            {
                result = DomainOperationResult.ElementNotInDomain;
                return;
            }

            this.size       = 1;
            this.lowerBound = this.upperBound = value - offset;
            result          = DomainOperationResult.InstantiateSuccessful;
        }
示例#11
0
        void IDomain <int> .InstantiateLowest(out DomainOperationResult result)
        {
            if (!IsInDomain(this.lowerBound - offset))
            {
                result = DomainOperationResult.ElementNotInDomain;
                return;
            }

            this.size       = 1;
            this.upperBound = this.lowerBound;
            result          = DomainOperationResult.InstantiateSuccessful;
        }
示例#12
0
        void IVariable <int> .Instantiate(int depth, out DomainOperationResult result)
        {
            var instantiatedDomain = (IDomain <int>) this.Domain.Clone();

            instantiatedDomain.Instantiate(out result);
            if (result != DomainOperationResult.InstantiateSuccessful)
            {
                throw new DeciderException("Failed to instantiate Variable.");
            }

            this.domainStack.Push(new DomInt(instantiatedDomain, depth));
        }
示例#13
0
        private void BackTrackVariable(IVariable <int> variablePrune, out DomainOperationResult result)
        {
            ++this.Backtracks;
            var value = variablePrune.InstantiatedValue;

            foreach (var variable in this.VariableList)
            {
                variable.Backtrack(this.Depth);
            }
            --this.Depth;

            variablePrune.Remove(value, this.Depth, out result);
        }
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            try
            {
                var category = new Category(Name);

                await SaveAsync(category, _categoryRepository);

                return(await OkAsync(DomainOperationResult.Create(category.Id)));
            }
            catch (Exception)
            {
                return(await FailAsync(ErrorCode.Exception));
            }
        }
示例#15
0
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var boothStaff = await _db.Set <BoothStaff>()
                             .FirstOrDefaultAsync(staff => staff.Id == Id);

            if (boothStaff == null)
            {
                return(await FailAsync(ErrorCode.NotFound));
            }

            _db.Set <BoothStaff>()
            .Remove(boothStaff);

            await _unitOfWork.SaveAsync();

            return(await OkAsync(DomainOperationResult.CreateEmpty()));
        }
示例#16
0
        void IVariable <int> .Remove(int value, int depth, out DomainOperationResult result)
        {
            if (this.domainStack.Peek().Depth != depth)
            {
                this.domainStack.Push(new DomInt((IDomain <int>) this.Domain.Clone(), depth));

                this.Domain.Remove(value, out result);

                if (result == DomainOperationResult.ElementNotInDomain)
                {
                    this.domainStack.Pop();
                }
            }
            else
            {
                this.Domain.Remove(value, out result);
            }
        }
示例#17
0
        void IDomain <int> .Remove(int element, out DomainOperationResult result)
        {
            result = DomainOperationResult.EmptyDomain;
            if (element < 0 || !IsInDomain(element))
            {
                result = DomainOperationResult.ElementNotInDomain;
                return;
            }

            RemoveFromDomain(element);

            if (this.size == 1)
            {
                this.size       = 0;
                this.lowerBound = this.upperBound + 1;
                return;
            }

            if (element == this.lowerBound)
            {
                this.lowerBound = element;
                while (this.lowerBound <= this.upperBound && !IsInDomain(this.lowerBound))
                {
                    ++this.lowerBound;
                    --this.size;
                }
            }
            else if (element == this.upperBound)
            {
                this.upperBound = element;
                while (this.upperBound >= this.lowerBound && !IsInDomain(this.upperBound))
                {
                    --this.upperBound;
                    --this.size;
                }
            }

            if (this.lowerBound > this.upperBound || this.size == 0)
            {
                return;
            }

            result = DomainOperationResult.RemoveSuccessful;
        }
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var booth = await _boothRepository.GetByIdAsync(Id);

            if (booth == null)
            {
                return(await FailAsync(ErrorCode.NotFound));
            }

            var address = new Address(Street,
                                      City);

            booth.ChangeDetails(Code,
                                address);

            await SaveAsync(booth, _boothRepository);

            return(await OkAsync(DomainOperationResult.Create(booth.Id)));
        }
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var boothStaff = await _db.Set <BoothStaff>()
                             .FirstOrDefaultAsync(staff => staff.Id == Id);

            var salary = new Salary(Salary);

            var phone = new Phone(PhoneNumber);

            boothStaff.ChangeDetails(FirstName,
                                     LastName,
                                     salary,
                                     phone);

            _db.Set <BoothStaff>()
            .Update(boothStaff);

            await _db.SaveChangesAsync();

            return(await OkAsync(DomainOperationResult.Create(boothStaff.Id)));
        }
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var product = await _productRepository.GetByIdAsync(Id);

            var photo = new Photo(PhotoUrl,
                                  PhotoWidth,
                                  PhotoHeight);

            var boothIds = BoothIds.ToArray()
                           .ToNewString();

            product.ChangeDetails(Name,
                                  Description,
                                  Price,
                                  boothIds,
                                  SupplierId,
                                  photo);

            await SaveAsync(product, _productRepository);

            return(await OkAsync(DomainOperationResult.Create(product.Id)));
        }
示例#21
0
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            try
            {
                var product = await _productRepository.GetByIdAsync(Id);

                if (product == null)
                {
                    return(await FailAsync(ErrorCode.NotFound));
                }

                product.RaiseDeleteEvent();

                _productRepository.Delete(product);
                await _unitOfWork.SaveAsync();

                return(await OkAsync(DomainOperationResult.CreateEmpty()));
            }
            catch (Exception)
            {
                return(await FailAsync(ErrorCode.Exception));
            }
        }
示例#22
0
        public async override Task <CommandExecutionResult> ExecuteAsync()
        {
            var photo = new Photo(PhotoUrl,
                                  PhotoWidth,
                                  PhotoHeight);

            var isValidSupplier = _db.Set <Domain.ProductManagement.ProductSupplier>()
                                  .FirstOrDefault(supplier => supplier.Id == ProductSupplierId);

            var boothIds = BoothIds.ToArray()
                           .ToNewString();

            var product = new Domain.ProductManagement.Product(Code,
                                                               Name,
                                                               Description,
                                                               Price,
                                                               boothIds,
                                                               ProductSupplierId,
                                                               photo);

            await SaveAsync(product, _productRepository);

            return(await OkAsync(DomainOperationResult.Create(product.Id)));
        }
示例#23
0
 void IDomain <int> .Instantiate(out DomainOperationResult result)
 {
     ((IDomain <int>) this).InstantiateLowest(out result);
 }