Beispiel #1
0
        public JournalEntryViewModel CreateBatchEntryViewModel(BatchEntryDto entry)
        {
            if (entry == null)
            {
                return(new JournalEntryViewModel());
            }
            else
            {
                var e = new JournalEntryViewModel
                {
                    Id             = entry.Id,
                    BatchId        = entry.BatchId,
                    Additions      = entry.Additions,
                    Bottled        = entry.Bottled,
                    Comments       = entry.Comments,
                    ActionDateTime = entry.ActionDateTime ?? entry.EntryDateTime,
                    EntryDateTime  = entry.EntryDateTime,
                    Filtered       = entry.Filtered,
                    pH             = entry.pH,
                    Racked         = entry.Racked,
                    So2            = entry.So2,
                    Sugar          = entry.Sugar,
                    SugarUomId     = entry.SugarUom?.Id,
                    SugarUom       = entry.SugarUom?.Abbreviation,
                    Ta             = entry.Ta,
                    Temp           = entry.Temp,
                    TempUomId      = entry.TempUom?.Id,
                    TempUom        = entry.TempUom?.Abbreviation
                };


                return(e);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> AddBatchEntryAsync(int id, [FromBody] BatchEntryViewModel batchEntry)
        {
            try
            {
                if (batchEntry == null)
                {
                    return(NoContent());
                }

                if (!batchEntry.HasEntryData())
                {
                    return(NoContent());
                }

                BatchEntryDto dto = new BatchEntryDto
                {
                    BatchId        = id,
                    Additions      = batchEntry.Additions,
                    Bottled        = batchEntry.Bottled,
                    Comments       = batchEntry.Comments,
                    EntryDateTime  = DateTime.Now,
                    ActionDateTime = batchEntry.ActionDateTime,
                    Filtered       = batchEntry.Filtered,
                    pH             = batchEntry.pH,
                    Racked         = batchEntry.Racked,
                    So2            = batchEntry.So2,
                    Sugar          = batchEntry.Sugar,
                    Ta             = batchEntry.Ta,
                    Temp           = batchEntry.Temp
                };

                if (batchEntry.SugarUomId.HasValue)
                {
                    var uom = _queryFactory.CreateBatchSugarUOMQuery();
                    dto.SugarUom = await uom.ExecuteAsync(batchEntry.SugarUomId.Value).ConfigureAwait(false);
                }

                if (batchEntry.TempUomId.HasValue)
                {
                    var uom = _queryFactory.CreateBatchTempUOMQuery();
                    dto.TempUom = await uom.ExecuteAsync(batchEntry.TempUomId.Value).ConfigureAwait(false);
                }

                var cmd      = _commandsFactory.CreateBatchEntriesCommand();
                var entryDto = await cmd.AddAsync(dto).ConfigureAwait(false);


                var model = _modelFactory.CreateBatchEntryViewModel(entryDto);

                return(Ok(model));
            }
            catch (Exception)
            {
                return(StatusCode(500));

                throw;
            }
        }