/// <summary> /// Maps Id, ReceiptId, Amount, Discount, Cost, /// Product(5), /// Changes(4), /// Participants(5) /// </summary> /// <param name="dto"></param> /// <returns></returns> /// <exception cref="NullReferenceException"></exception> public static ReceiptRowAllDTO FromBLL(BLLReceiptRowDTO dto) { if (dto == null) { throw new NullReferenceException("Can't map, BLLReceiptRowDTO is null"); } var result = new ReceiptRowAllDTO() { ReceiptId = dto.ReceiptId, Product = ProductMapper.FromBLL(dto.Product), Amount = dto.Amount, Discount = dto.Discount, CurrentCost = dto.CurrentCost, ReceiptRowId = dto.ReceiptRowId, Changes = new List <ChangeDTO>(), Participants = new List <RowParticipantDTO>() }; foreach (var changeDto in dto.Changes) { result.Changes.Add(ChangeMapper.FromBLL(changeDto)); } foreach (var participantDTO in dto.Participants) { result.Participants.Add(RowParticipantMapper.FromBLL(participantDTO)); } return(result); }
/// <summary> /// Maps ReceiptId, ProductId, Amount, Discount /// </summary> /// <param name="dto"></param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public static DALReceiptRowDTO FromBLL(BLLReceiptRowDTO dto) { if (dto == null) { throw new NullReferenceException("Can't map, BLLReceiptRowDTO is null"); } if (dto.Amount == null || dto.ProductId == null || dto.ReceiptId == null) { return(null); } return(new DALReceiptRowDTO() { Amount = dto.Amount.Value, Discount = dto.Discount, ProductId = dto.ProductId.Value, ReceiptId = dto.ReceiptId.Value }); }
public async Task <BLLReceiptRowDTO> UpdateRowAmount(BLLReceiptRowDTO dto, int userId) { if (dto?.ReceiptRowId == null || dto.Amount == null) { return(null); } var rowId = await Uow.ReceiptRows.UpdateRowAmount(dto.ReceiptRowId.Value, dto.Amount.Value, userId); if (rowId == null) { return(null); } await Uow.SaveChangesAsync(); var row = await Uow.ReceiptRows.FindRowAndRelatedDataAsync(rowId.Value); return(ReceiptRowMapper.FromDAL(row)); }
public async Task <BLLReceiptRowDTO> AddRow(BLLReceiptRowDTO receiptRowDTO, int currentUserId) { if (receiptRowDTO == null) { return(null); } var receiptRow = ReceiptRowMapper.FromBLL(receiptRowDTO); if (receiptRow == null) { return(null); } if (receiptRow.Amount < 0) { return(null); } if (receiptRow.Discount.HasValue && (receiptRow.Discount.Value < 0.0m || receiptRow.Discount.Value > 1.0m)) { return(null); } if (!receiptRow.ReceiptId.HasValue) { return(null); } if (!receiptRow.ProductId.HasValue) { return(null); } var receipt = await Uow.Receipts.FindReceiptAsync(receiptRow.ReceiptId.Value); var product = await Uow.Products.FindDTOAsync(receiptRow.ProductId.Value); if (receipt == null || receipt.IsFinalized || receipt.ReceiptManagerId != currentUserId) { return(null); } if (product == null) { return(null); } var addedRowId = await Uow.ReceiptRows.AddAsync(receiptRow); if (addedRowId == null) { return(null); } await Uow.SaveChangesAsync(); var newId = Uow.ReceiptRows.GetEntityIdAfterSaveChanges(addedRowId.Value); if (newId == null) { return(null); } var row = await Uow.ReceiptRows.FindRowAndRelatedDataAsync(newId.Value); return(ReceiptRowMapper.FromDAL(row)); }