Ejemplo n.º 1
0
        public async Task Handle(UpdateOrderItemsCmd message)
        {
            try
            {
                _logger.InsertLog(LogLevel.Information, "Get order", String.Format("AggregateId = {0}, Version = {1}, Number items = {2}", message.Id, message.ExpectedVersion, message.CommandModel.UpdatedOrderItems.Count));
                var order = await _session.Get <CurrentOrder>(message.Id, message.ExpectedVersion);

                _logger.InsertLog(LogLevel.Information, "Order Information", String.Format("AggregateId = {0}, Version = {1}, Number items = {2}", order.Id, order.Version, order.OrderItems.Count));
                foreach (var item in order.OrderItems)
                {
                    _logger.InsertLog(LogLevel.Information, "Existing Order Item", String.Format("AggregateId = {0}, Product Id = {1}, Quantity = {2}", item.OrderItemGuid, item.ProductId, item.Quantity));
                }

                foreach (var item in message.CommandModel.UpdatedOrderItems)
                {
                    if (item.Id != 0)
                    {
                        _logger.InsertLog(LogLevel.Information, "Change order item quantity", String.Format("AggregateId = {0}, Product Id = {1}, Quantity = {2}", item.AggregateId, item.ProductId, item.Quantity));
                        order.ChangeOrderItemQuantity(item.AggregateId, item.ProductId, item.Quantity);
                    }
                    else
                    {
                        _logger.InsertLog(LogLevel.Information, "Add order item", String.Format("AggregateId = {0}, Product Id = {1}, Quantity = {2}", item.AggregateId, item.ProductId, item.Quantity));
                        order.AddOrderItem(CompGuid.NewGuid(), item.ProductId, item.Quantity);
                    }
                }
                await _session.Commit();
            }
            catch (Exception ex)
            {
                _logger.InsertLog(LogLevel.Error, "Handle command UpdateOrderItemsCmd error", ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public CurrentOrder(CreateCmd message)
        {
            List <CreatedEvent.OrderItem> orderItems = new List <CreatedEvent.OrderItem>();

            foreach (var item in message.CommandModel.AddedOrderItems)
            {
                orderItems.Add(new CreatedEvent.OrderItem(CompGuid.NewGuid(), item.ProductId, item.Quantity));
            }
            ApplyChange(new CreatedEvent(message.Id, message.CommandModel.TableId, orderItems));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(string jsonModel, CancellationToken cancellationToken)
        {
            if (!_permissionService.Authorize(XrmsPermissionProvider.ManageWaiterOrders))
            {
                return(AccessDeniedView());
            }

            if (!String.IsNullOrEmpty(jsonModel))
            {
                try
                {
                    CreateInStoreOrderModel model = JsonConvert.DeserializeObject <CreateInStoreOrderModel>(jsonModel);

                    // validate model
                    CreateInStoreOrderModelValidator validator = new CreateInStoreOrderModelValidator(this._localizationService);
                    ValidationResult results = validator.Validate(model);

                    if (!results.IsValid)
                    {
                        _logger.InsertLog(LogLevel.Error, "Create Order: Validation Error", results.ToString());
                        List <string> errorList = new List <string>();
                        foreach (var failure in results.Errors)
                        {
                            //Console.WriteLine("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage);
                            errorList.Add(failure.ErrorMessage);
                        }
                        return(BadRequest(errorList));
                    }

                    // no error, send command
                    Guid guid = CompGuid.NewGuid();
                    await _commandSender.Send(new CreateCmd(guid, model), cancellationToken);

                    return(Ok(guid));
                }
                catch (Exception ex)
                {
                    _logger.InsertLog(LogLevel.Error, "Create Order: Exception Error", ex.Message);
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }
            else
            {
                _logger.InsertLog(LogLevel.Error, "Create Order: Empty Object", "Request object is null or empty.");
                return(BadRequest("Request object is null or empty."));
            }
        }
Ejemplo n.º 4
0
        public virtual IActionResult Create(CreateTableModel model, bool continueEditing, CancellationToken cancellationToken)
        {
            if (!_permissionService.Authorize(XrmsPermissionProvider.ManageTables))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                /*var group = model.ToEntity();
                 * group.CreatedOnUtc = DateTime.UtcNow;
                 * group.UpdatedOnUtc = DateTime.UtcNow;
                 * _materialGroupService.InsertTable(group);*//*_context.Add(table);
                 * await _context.SaveChangesAsync();
                 * return RedirectToAction("Index");*/
                Guid guid = CompGuid.NewGuid();
                _commandSender.Send(new CreateCmd(guid, "", model.Name, 0, Guid.Empty, model.Description), cancellationToken);
                //return RedirectToAction("Index");



                var table = this._materialGroupService.GetTableByAggregateId(guid);

                //activity log
                _customerActivityService.InsertActivity("AddNewTable", _localizationService.GetResource("Xrms.ActivityLog.AddNewTable"), table);

                SuccessNotification(_localizationService.GetResource("Xrms.Admin.Catalog.Tables.Notifications.Created"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();
                    return(RedirectToAction("Edit", new { id = table.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            var viewModel = new TableDetailsPageViewModel();

            model.ToDetailsViewModel(viewModel);
            //viewModel.TableInfo = model;

            return(View("~/Plugins/Xrms/Areas/Admin/Views/Table/Create.cshtml", viewModel));
        }