public static string StartTask(string guid, string taskName) { try { // Create a new contract with a GUID identifier, add a handle to the task that will be executed. using (var c = new ContractSchedule(guid, taskName)) { // Adds an ACTION with delegate to the method that will perform the task c.ActionTask = delegate { // Delegated method receiving parameter with processing status Loading(c.Status); }; // Add task in processing queue QueueJob.AddTask(new ScheduledTask(c, c.ActionTask)); } return("true"); } catch (Exception e) { Console.WriteLine(e); return(JsonConvert.SerializeObject("false")); } }
public async Task <Result> Handle(CreateMasterTradingAgreementCommand request, CancellationToken cancellationToken) { var counterparty = _staticData.Companies[request.CounterpartyId]; if (counterparty is null) { return(ResultFactory.RecordNotFound("Company", request.CounterpartyId)); } _db.Attach(counterparty).State = EntityState.Unchanged; var type = (MasterTradingAgreementType)request.Type; var duration = new DateRange(request.DurationStartDate, request.DurationEndDate); var entity = new MasterTradingAgreement(request.Name, type, duration, counterparty, request.Comments); foreach (var dto in request.ContractSchedules) { var location = _staticData.Locations[dto.LocationId]; if (location is null) { return(ResultFactory.RecordNotFound("Location", dto.LocationId)); } _db.Attach(location).State = EntityState.Unchanged; var scheduleType = (ContractScheduleType)request.Type; var scheduleDuration = new DateRange(request.DurationStartDate, request.DurationEndDate); var schedule = new ContractSchedule(dto.Name, scheduleType, scheduleDuration, dto.Comments, entity, location); entity.AddContractSchedule(schedule); } _db.MasterTradingAgreements.Add(entity); await _db.SaveChangesAsync(cancellationToken); return(Result.Ok() .WithReason(new RecordsCreatedSuccess(entity.Id))); }