public async Task <IActionResult> Create(TransactionActionViewModel model) { if (ModelState.IsValid) { var username = User.Identity.Name; var user = await _userManager.FindByNameAsync(username); var profile = await _profileService.GetProfileByUserId(user.Id); var transactionDto = new TransactionsDto { Description = model.Description, Comment = model.Comment, Amount = model.Amount, //Currency CurrencyType = 933, CreationTime = DateTime.Now, ProfileId = profile.Id, GroupId = model.GroupId, }; await _transactionsService.AddAsync(transactionDto); return(RedirectToAction("Detail", "Group", new { id = model.GroupId })); } return(View(model)); }
public async Task <IActionResult> Add([FromBody] string newTransaction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { return(Unauthorized("Token is invalid")); } var result = await transactionsService.AddAsync(userId, newTransaction); if (result <= 0) { return(StatusCode(500, "Error has occured while adding transaction")); } return(Ok(result)); }