using Admin.Models.EReturn; using BusinessLogic.Interfaces.Services; using log4net; using System; using System.Collections.Generic; using System.Linq; namespace Admin.Classes.Commands.EReturn { public class ApproverEditCommand : BaseCommand { private readonly IEReturnService _eReturnService; public ApproverEditCommand(ILog log , IEReturnService eReturnService) : base(log) { _eReturnService = eReturnService ?? throw new ArgumentNullException("eReturnService"); } protected override CommandResult OnExecute(EditViewModel model) { var transactions = new List(); var item = new BusinessLogic.Entities.EReturn() { Id = model.EReturn.EReturn.Id, PendingTransactions = model.Transactions.Select(x => new BusinessLogic.Entities.PendingTransaction() { Amount = x.Amount, Id = x.Id }).ToList(), }; if (model.Cash != null) { item.EReturnCashes = new List() { new BusinessLogic.Entities.EReturnCash() { Id = model.Cash.Id, EReturnId = model.EReturn.EReturn.Id, BagNumber = model.Cash.BagNumber, Pounds50 = model.Cash.Pounds50, Pounds20 = model.Cash.Pounds20, Pounds10 = model.Cash.Pounds10, Pounds5 = model.Cash.Pounds5, Pounds2 = model.Cash.Pounds2, Pounds1 = model.Cash.Pounds1, Pence50 = model.Cash.Pence50, Pence20 = model.Cash.Pence20, Pence10 = model.Cash.Pence10, Pence5 = model.Cash.Pence5, Pence2 = model.Cash.Pence2, Pence1 = model.Cash.Pence1, Total = model.Cash.Total } }; } if (model.Cheques != null && model.Cheques.Any()) { item.EReturnCheques = model.Cheques.Select(x => new BusinessLogic.Entities.EReturnCheque() { Id = x.Id, Amount = x.Amount, Name = x.Name, ItemNo = x.ItemNo }).ToList(); } var result = _eReturnService.Update(item); return new CommandResult(result); } } }