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); }
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(); }
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)); } }
public void CreateWidget(Widget widget) { widgetRepository.Add(widget); }