コード例 #1
0
        public WidgetViewModelBase Create(WidgetViewModelBase widgetView)
        {
            var        widgetType = TypeHelper.FindType(widgetView.Type.ToString());
            WidgetBase widget     = (WidgetBase)Activator.CreateInstance(widgetType);

            _widgetViewModelToWidgetBase.CreateMapper().Map(widgetView, widget);
            _widgetRep.Add(widget);
            _widgetRep.Save();
            widgetView.WidgetId = widget.WidgetId;
            return(widgetView);
        }
コード例 #2
0
        public async Task HandleMessage(WidgetCreationCommand content, IMessageContext messageContext, CancellationToken cancellationToken)
        {
            var widget = WidgetMap.ToEntity(content.Data);
            await _widgetRepository.Add(widget);

            var createdResource = WidgetMap.ToResource(widget);
            var principal       = messageContext.Principal;
            var identity        = principal?.Identity;
            var requestor       = identity?.Name;
            var reply           = new WidgetCreationReply(createdResource);
            await messageContext.Bus.Publish(new WidgetEvent("WidgetCreated", createdResource, requestor), "WidgetEvents", cancellationToken);

            await messageContext.SendReply(reply, cancellationToken : cancellationToken);

            messageContext.Acknowledge();
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] RequestDocument <WidgetResource> request)
        {
            try
            {
                var widget = WidgetMap.ToEntity(request.Data ?? new WidgetResource());
                await _widgetRepository.Add(widget);

                var createdResource = WidgetMap.ToResource(widget);
                await _bus.Publish(new WidgetEvent("WidgetCreated", createdResource, GetRequestor()), "WidgetEvents");

                return(CreatedAtAction("Post", createdResource));
            }
            catch (WidgetAlreadyExistsException)
            {
                return(new StatusCodeResult((int)HttpStatusCode.Conflict));
            }
        }
コード例 #4
0
 public void CreateWidget(Widget widget)
 {
     widgetRepository.Add(widget);
 }