public async Task DressingSave(DressingViewModel viewModel, SharedDomain sharedDomain) { List <NTError> errors = new List <NTError>(); //validating BlockNumbers string[] blockNumbers = viewModel.Model.Blocks.Select(m => m.BlockNumber).ToArray(); List <BlockStateModel> blockStates = await sharedDomain.BlockStatesGet(blockNumbers); string[] invalidBlockNumbers = blockNumbers.Except(blockStates.Where(b => b.State == (int)State.Excavate).Select(b => b.BlockNumber)).ToArray(); if (invalidBlockNumbers.Length > 0) { errors.Add(new NTError() { Description = String.Format(PlantMessages.BlockNumbersInvalid, String.Join(", ", invalidBlockNumbers)) }); } //validating time for Stoppages if (!viewModel.MachineStoppages.ValidateTimeRange()) { errors.Add(new NTError() { Description = PlantMessages.StoppageTimeRangeInvalid }); } //checking for one operator if (viewModel.MachineOperators.Count == 0) { errors.Add(new NTError() { Description = PlantMessages.OperatorRequired }); } else if (!viewModel.MachineOperators.ValidateTimeRange()) { errors.Add(new NTError() { Description = PlantMessages.OperatorTimeRangeInvalid }); } if (errors.Count > 0) { throw new NTException(PlantMessages.DressingError, errors); } //saving the Block Dressing await plantRepository.DressingSave(viewModel); //finally saving the state info foreach (var state in blockStates) { state.State = (int)State.Dress; } await sharedDomain.BlockStatesSave(blockStates); }