public virtual async Task <IActionResult> Command([FromBody] ActionDto action) { if (action == null) { return(Error(Messages.RequestInvalid)); } bool isCommand = false; if (_cqrsMediator.CqrsCommandSubscriptionManager.HasSubscriptionsForCommand(action.Type)) { isCommand = true; } if (string.IsNullOrWhiteSpace(action.Type) || (!isCommand)) { return(Error(Messages.ActionInvalid)); } if (!ModelState.IsValid) { return(ValidationErrors(ModelState)); } Type payloadType; CancellationTokenSource cts; cts = TaskHelper.CreateNewCancellationTokenSource(); payloadType = _cqrsMediator.CqrsCommandSubscriptionManager.GetCommandTypeByName(action.Type); //command if (payloadType != null) { string payloadString = JsonConvert.SerializeObject(action.Payload); dynamic typedPayload = JsonConvert.DeserializeObject(payloadString, payloadType); var actionForValidation = new ActionDto() { Type = action.Type, Payload = typedPayload }; if (!TryValidateModel(actionForValidation)) { return(ValidationErrors(ModelState)); } dynamic result = await _cqrsMediator.DispatchAsync(typedPayload, cts.Token); return(FromResult(result)); } else { //dynamic command string payloadString = JsonConvert.SerializeObject(action.Payload); Result <dynamic> result = await _cqrsMediator.DispatchCommandAsync(action.Type, payloadString, cts.Token); return(FromResult(result)); } }
public async virtual Task <Result> TriggerActionAsync(object id, ActionDto action, string triggeredBy, CancellationToken cancellationToken = default(CancellationToken)) { var result = await DomainService.TriggerActionAsync(id, action.Action, triggeredBy, cancellationToken).ConfigureAwait(false); if (result.IsFailure) { switch (result.ErrorType) { case ErrorType.ObjectValidationFailed: return(result); case ErrorType.DatabaseValidationFailed: return(result); case ErrorType.ObjectDoesNotExist: return(result); case ErrorType.ConcurrencyConflict: return(result); default: throw new ArgumentException(); } } return(Result.Ok()); }
public virtual async Task <IActionResult> TriggerAction(string id, [FromBody] ActionDto action) { if (action == null) { return(ApiErrorMessage(Messages.RequestInvalid)); } if (string.IsNullOrWhiteSpace(action.Action) || !actionEvents.IsValidAction <TUpdateDto>(action.Action)) { return(ApiErrorMessage(Messages.ActionInvalid)); } if (!ModelState.IsValid) { return(ValidationErrors(ModelState)); } var cts = TaskHelper.CreateNewCancellationTokenSource(); var result = await Service.TriggerActionAsync(id, action, Username, cts.Token); if (result.IsFailure) { return(ValidationErrors(result)); } return(NoContent()); }
public void Send(ActionDto userAction) { try { lock (_sync) { if (userAction != null) { if (_actionList.Count == _maxItemsLimit) { _actionList.RemoveRangeByIndexes(0, _actionList.Count / 2); } _actionList.Add(userAction); } } } catch (InvalidOperationException ex) { _messageService.ShowError(ex.Message); } catch (IndexOutOfRangeException ex) { _messageService.ShowError(ex.Message); } }
public virtual Result TriggerAction(object id, ActionDto action, string triggeredBy) { var result = DomainService.TriggerAction(id, action.Action, triggeredBy); if (result.IsFailure) { switch (result.ErrorType) { case ErrorType.ObjectValidationFailed: return(result); case ErrorType.DatabaseValidationFailed: return(result); case ErrorType.ObjectDoesNotExist: return(result); case ErrorType.ConcurrencyConflict: return(result); default: throw new ArgumentException(); } } return(Result.Ok()); }
public HttpResponseMessage Delete(ActionDeleteModel actionDeleteModel) { ActionDto actionDto = this.mapper.Map <ActionDeleteModel, ActionDto>(actionDeleteModel); this.actionAppService.RemoveExistingAction(actionDto); return(new HttpResponseMessage(HttpStatusCode.OK)); }
// This is the simplest implementation usual in CRUD scenarios // or CRUD scenarios with additional validation. // In complex scenarios creating a new entity and editing existing // once can differ significantly. In that case we recommend to // split this method into two or more. public async Task <ServiceResult <ActionDto> > CreateOrUpdate(ActionDto actionDto) { // Either create a new entity based on the DTO // or change an existing one based on the DTO. Action action = actionDto.RepresentsNewEntity ? actionDto.TranslateTo <Action>() : (await _actionRepository.GetById(actionDto.Id)).CopyPropertiesFrom(actionDto); // Check if the entity exists (if it was an update). if (action == null) { return(EntityNotFound(actionDto)); } // TODO: Later on we will do the checks here. // So far we assume everything always works fine. // Save changes. action = await _actionRepository.AddOrUpdate(action); // If the DTO was representing a new DTO // we need to set the assigned Id. // If it already had the Id, it is the same one. // So we can simply have an assignment here. actionDto.Id = action.Id; // Remove ActionsAll from cache, next time getall call will fill the cache. CacheHelper cacheHelper = new CacheHelper(_memoryCache); cacheHelper.RemoveActions(); return(Ok(actionDto)); }
public HttpResponseMessage UpdateActionByCustomerId(ActionCustomerUpdateModel actionCustomerUpdateModel) { ActionDto actionDto = this.mapper.Map <ActionCustomerUpdateModel, ActionDto>(actionCustomerUpdateModel); this.actionAppService.UpdateExistingActionByCustomerId(actionDto); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public HttpResponseMessage Insert(ActionCreateModel actionCreateModel) { ActionDto actionDto = this.mapper.Map <ActionCreateModel, ActionDto>(actionCreateModel); this.actionAppService.CreateNewAction(actionDto); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public ActionViewModel Get(long id) { ActionDto actionDto = actionAppService.Get(id); ActionViewModel actionViewModel = this.mapper.Map <ActionViewModel>(actionDto); return(actionViewModel); }
public void UpdateExistingActionsBySalesChannel(ActionDto actionDto) { // 1st way using UpdateExistingActionByCustomer //using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create()) //{ // connection.Open(); // using (NpgsqlTransaction transaction = connection.BeginTransaction()) // { // try // { // IEnumerable<long> customerIds = this.customerSalesChannelService.SelectCustomerIdsByCustomerService(connection, actionDto.SalesChannelId); // foreach (long customerId in customerIds) // { // actionDto.CustomerId = customerId; // ActionEntity action = this.dtoToEntityMapper.Map<ActionDto, ActionEntity>(actionDto); // this.actionService.UpdateByCustomerId(connection, action); // } // transaction.Commit(); // } // catch(Exception ex) // { // transaction.Rollback(); // Console.WriteLine(ex.Message); // } // } //} // 2nd way: Using SalesChannelId only using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create()) { DomainLayer.Entities.ActionEntities.Action action = this.dtoToEntityMapper.Map <ActionDto, DomainLayer.Entities.ActionEntities.Action>(actionDto); this.actionService.UpdateBySalesChannelId(connection, action); } }
public void CreateNewAction(ActionDto actionDto) { using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create()) { DomainLayer.Entities.ActionEntities.Action action = this.dtoToEntityMapper.Map <ActionDto, DomainLayer.Entities.ActionEntities.Action>(actionDto); this.actionService.Insert(connection, action); } }
public IEnumerable <Action> SelectByCustomerId(IDbConnection connection, ActionDto actionDto, IDbTransaction transaction = null) { return(connection.Query <Action>(ActionQueries.SelectByCustomerId, new { productId = actionDto.ProductId, customerId = actionDto.CustomerId })); }
/// <summary> /// Execute an action. /// </summary> /// <param name="action">Action to execute.</param> /// <returns>Process result.</returns> internal static bool Execute(ActionDto action) { ZService service = new ZService(); var allLodes = service.GetNodes(); var node = allLodes.FirstOrDefault(x => x.HomeIdentifier == action.HomeIdentifier && x.ZIdentifier == action.ZIdentifier); node.ValueProxy = action.Value; return service.Set(node); }
public IActionResult NewAction([FromBody] ActionDto dto) { AssertTrackRequestSource(Request.HttpContext.Connection); _sutController.NewAction(dto); return(NoContent()); }
public void UpdateExistingActionByCustomerId(ActionDto actionDto) { using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create()) { DomainLayer.Entities.ActionEntities.Action action = this.dtoToEntityMapper.Map <ActionDto, DomainLayer.Entities.ActionEntities.Action>(actionDto); this.actionService.UpdateByCustomerId(connection, action); } }
public async Task <ActionDto> Add(ActionDto actionDto) { var action = Mapper.Map <Action>(actionDto); action.Id = ObjectId.GenerateNewId().ToString(); var result = await _repository.AddAsync(action).ConfigureAwait(false); return(result == null ? null : Mapper.Map <ActionDto>(result)); }
private void AssertAction(ActionDto actionDto, Action action) { Assert.AreEqual(action.Id, actionDto.Id); Assert.AreEqual(action.IsOverDue(), actionDto.IsOverDue); Assert.AreEqual(action.Title, actionDto.Title); Assert.AreEqual(action.IsClosed, actionDto.IsClosed); Assert.AreEqual(action.DueTimeUtc, actionDto.DueTimeUtc); Assert.AreEqual(action.Attachments.Count, actionDto.AttachmentCount); }
public Models.Action mapActionDtoToAction(ActionDto ActionDto) { Models.Action Action = new Models.Action(); Action.Description = ActionDto.Description; Action.Name = ActionDto.Name; Action.Id = ActionDto.Id; Action.Type = ActionDto.Type; return(Action); }
public ActionDto Get(long id) { using (NpgsqlConnection connection = this.databaseConnectionFactory.Instance.Create()) { DomainLayer.Entities.ActionEntities.Action actionEntity = this.actionService.SelectById(connection, id); ActionDto actionDto = this.dtoToEntityMapper.MapView <DomainLayer.Entities.ActionEntities.Action, ActionDto>(actionEntity); return(actionDto); } }
/// <summary> /// 修改操作 /// </summary> /// <param name="dto">传入操作信息</param> public void ModifyAction(ActionDto dto) { AuthAction entity = _actionRepository.Get(dto.Id); entity.Name = dto.Name; entity.Template = dto.Template; entity.Description = dto.Description; _actionRepository.Update(entity); }
// POST api/<controller> public async Task <IHttpActionResult> Post(ActionDto actionDto) { var errorMessage = await _actionValidator.ValidateAction(actionDto); if (!string.IsNullOrEmpty(errorMessage)) { return(BadRequest(errorMessage)); } return(Ok(await _actionsService.Add(actionDto))); }
public ActionDto mapActionToActionDto(Models.Action Action) { ActionDto ActionDto = new ActionDto(); ActionDto.Description = Action.Description; ActionDto.Name = Action.Name; ActionDto.Id = Action.Id; ActionDto.Type = Action.Type; return(ActionDto); }
public bool InsertOrUpdate(ActionDto dto) { if (dto.Id > 0) { return(_actionRepository.UpdateEntity(Mapper.Map <Actions>(dto))); } else { return(_actionRepository.InsertEntity(Mapper.Map <Actions>(dto))); } }
/** * As some heuristics are based on which action (eg HTTP call, or click of button) * in the test sequence is executed, and their order, we need to keep track of which * action does cover what. * * @param dto the DTO with the information about the action (eg its index in the test) */ //TODO: Complete this method. Man: modified, please check public void NewAction(ActionDto dto) { // if (dto.index > extras.size()) { // extras.add(computeExtraHeuristics()); // } // this.actionIndex = dto.index; // // resetExtraHeuristics(); NewActionSpecificHandler(dto); }
public ActionResult ActionEdit(string id) { if (string.IsNullOrEmpty(id)) { return(PartialView("_editForm", new ActionDto())); } else { ActionDto btnDto = _actionService.GetAction(id); return(PartialView("_editForm", btnDto)); } }
public virtual Task <IActionResult> QueryFromRoute([FromRoute] string type) { var payload = Request.Query; var action = new ActionDto() { Type = type, Payload = ToDynamic(payload) }; return(QueryFromJson(action)); }
public async Task <ActionDto> Update(ActionDto actionDto) { var action = await _repository.GetByIdAsync(actionDto.Id).ConfigureAwait(false); if (action == null) { return(null); } action = Mapper.Map(actionDto.FixMeUp(), action); var result = await _repository.UpdateAsync(action).ConfigureAwait(false); return(result == null ? null : Mapper.Map <ActionDto>(result)); }
public void Properties_GetSetWorkedCorrectly() { const string name = "SomeName"; const string version = "SomeVersion"; DateTime timestamp = DateTime.Now; var dbAction = new ActionDto { Name = name, Timestamp = timestamp, Version = version }; Assert.Equal(name, dbAction.Name); Assert.Equal(version, dbAction.Version); Assert.Equal(timestamp, dbAction.Timestamp); }
// PUT api/<controller>/5 public async Task <IHttpActionResult> Put(string id, ActionDto actionDto) { if (actionDto.Id != id || string.IsNullOrEmpty(id)) { return(BadRequest()); } var errorMessage = await _actionValidator.ValidateAction(actionDto); if (!string.IsNullOrEmpty(errorMessage)) { return(BadRequest(errorMessage)); } return(Ok(await _actionsService.Update(actionDto))); }
private void AssertAction(ActionDto actionDto, Action action, PCSPlant plant, Project project) { AssertEqualAndNotNull(plant.Id, actionDto.PlantId); AssertEqualAndNotNull(plant.Title, actionDto.PlantTitle); AssertEqualAndNotNull(project.Name, actionDto.ProjectName); AssertEqualAndNotNull(project.Description, actionDto.ProjectDescription); Assert.AreEqual(project.IsClosed, actionDto.ProjectIsClosed); AssertEqualAndNotNull(action.Id, actionDto.Id); Assert.AreEqual(action.IsOverDue(), actionDto.IsOverDue); AssertEqualAndNotNull(action.Title, actionDto.Title); AssertEqualAndNotNull(action.Description, actionDto.Description); Assert.AreEqual(action.IsClosed, actionDto.IsClosed); Assert.AreEqual(action.DueTimeUtc, actionDto.DueTimeUtc); AssertEqualAndNotNull(action.Attachments.Count, actionDto.AttachmentCount); }