Ejemplo n.º 1
0
        public async Task <IActionResult> GetMaintenanceJobAsync(DateTime planningDate, Guid jobId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // get planning
                    var aggregateId = WorkshopPlanningId.Create(planningDate);
                    var planning    = await _planningRepo.GetByIdAsync(aggregateId);

                    if (planning == null || planning.Jobs == null)
                    {
                        return(NotFound());
                    }
                    // get job
                    var job = planning.Jobs.FirstOrDefault(j => j.Id == jobId);
                    if (job == null)
                    {
                        return(NotFound());
                    }
                    return(Ok(job.MapToDTO()));
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    throw;
                }
            }
            return(BadRequest());
        }
        public async Task <WorkshopPlanning> HandleCommandAsync(DateTime planningDate, FinishMaintenanceJob command)
        {
            // get planning
            var aggregateId = WorkshopPlanningId.Create(planningDate);
            var planning    = await _planningRepo.GetByIdAsync(aggregateId);

            if (planning == null)
            {
                return(null);
            }

            // handle command
            planning.FinishMaintenanceJob(command);

            // persist
            IEnumerable <Event> events = planning.GetEvents();
            await _planningRepo.SaveAsync(
                planning.Id, planning.OriginalVersion, planning.Version, events);

            // publish event
            foreach (var e in events)
            {
                await _messagePublisher.PublishMessageAsync(e.MessageType, e, "");
            }

            // return result
            return(planning);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetByDate(DateTime planningDate)
        {
            try
            {
                var aggregateId = WorkshopPlanningId.Create(planningDate);
                var planning    = await _planningRepo.GetByIdAsync(aggregateId);

                if (planning == null)
                {
                    return(NotFound());
                }

                return(Ok(planning.MapToDTO()));
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw;
            }
        }