public async Task <TransactionTypeDTO> Add(string name, string extension, IFormFile formFile) { if (formFile.Length != 0) { var fileId = Guid.NewGuid(); //var path = Path.Combine(Directory.GetCurrentDirectory(), $"{fileId}.{extension}"); var path = Path.Combine(Directory.GetCurrentDirectory(), "images", $"{fileId}.{extension}"); using (var stream = new FileStream(path, FileMode.Create)) { var copyTask = formFile.CopyToAsync(stream); var type = new TransactionTypeDTO() { Id = fileId, Name = name, Extension = extension }; var addTransactionTask = _transactionTypeRepo.Add(_mapper.Map <TransactionType>(type)); await Task.WhenAll(copyTask, addTransactionTask); _db.Commit(); return(type); } } return(null); }
public async Task UpdateItem(TransactionTypeDTO transactionType) { var transactionTypeEntity = _mapper.Map <TransactionType>(transactionType); _dbContext.TransactionTypes.Update(transactionTypeEntity); await _dbContext.SaveChangesAsync(); }
public static async Task <TransactionType> ToTransactionType( this TransactionTypeDTO dto, IRepository <TransactionType> transactionTypeRepository) => new TransactionType() { Id = dto.Id, Name = dto.Name, ReverseType = await transactionTypeRepository.GetByIdAsync(dto.ReverseTypeId), TypeStatus = (TypeStatuses)Enum.GetValues(typeof(TypeStatuses)).GetValue(dto.TypeStatusId) };
public static async Task <TransactionType> ToEntityAsync( this TransactionTypeDTO item, IRepository <TransactionType> transactionTypeRepository, CancellationToken token) => new TransactionType( new Identificator(item.Id), item.Name, await transactionTypeRepository.GetByIdAsync(new Identificator(item.ReverseTypeId), token), (TypeVariation)Enum.GetValues(typeof(TypeVariation)).GetValue(item.TypeVariationId));
public async Task Update(Guid id, string name, string extension, IFormFile formFile) { var typeDTO = new TransactionTypeDTO() { Id = id, Extension = extension, Name = name }; var type = _mapper.Map <TransactionType>(typeDTO); await _transactionTypeRepo.Update(type); _db.Commit(); }
public async Task <ActionResult> PostTransactionType(TransactionTypeDTO transactionTypeDTO) { try { await _service.InsertItem(transactionTypeDTO); return(CreatedAtAction("GetTransactionType", new { id = transactionTypeDTO.TransactionTypeId }, transactionTypeDTO)); } catch (Exception ex) { Log.LogError($"Chyba při ukládání do databáze: {ex.InnerException}"); return(NotFound()); } }
/// Receive all transactions by type public IEnumerable <TransactionDTO> GetTransactionByType(int cardId, TransactionTypeDTO type) { if (cardId <= 0) { throw new ArgumentException("This userId doesn't exist"); } var trans = Database.Transactions.GetTransactionsWithType(cardId, (int)type); if (trans == null || trans.Count() == 0) { throw new ValidationException($"Transactions by type {type.ToString()} not found", "Transactions"); } var mapper = new MapperConfiguration(conf => conf.CreateMap <Transactions, TransactionDTO>() .ForMember(x => x.CardId, x => x.MapFrom(m => m.Card.Id)) .ForMember(x => x.Type, x => x.MapFrom(m => m.Type))) .CreateMapper(); return(mapper.Map <IEnumerable <Transactions>, List <TransactionDTO> >(trans)); }
public async Task <IActionResult> PutTransactionType(int id, TransactionTypeDTO transactionTypeDTO) { if (id != transactionTypeDTO.TransactionTypeId) { Log.LogError($"Chyba!!! Záznam s tímto Id nebyl nalezen."); return(BadRequest()); } try { await _service.UpdateItem(transactionTypeDTO); return(CreatedAtAction("GetTransactionType", new { id = transactionTypeDTO.TransactionTypeId }, id)); } catch (Exception ex) { Log.LogError($"Chyba při ukládání do databáze: {ex.InnerException}"); return(NotFound()); } }