public async Task <IHttpActionResult> CreateTransaction(TransactionCreateViewModel model) { try { var transactionApi = new TransactionApi(); var UserManager = Request.GetOwinContext().GetUserManager <ApplicationUserManager>(); var user = await UserManager.FindByNameAsync(model.Username); var userId = user.Id; model.TransactionDate = DateTime.Now; model.AspNetUserId = userId; model.EndTime = model.TransactionDate.AddHours(model.Duration); var transaction = transactionApi.CreateTransaction(model); var parkingLot = (new ParkingLotApi()).Get(model.ParkingLotId); transaction.TransactionCode = parkingLot.Address + transaction.Id + ""; transactionApi.Edit(transaction.Id, transaction); TransactionCreateReturnViewModel result = new TransactionCreateReturnViewModel() { Id = transaction.Id, Amount = transaction.Amount, AspNetUserId = transaction.AspNetUserId, CarParkId = transaction.CarParkId, EndTime = transaction.EndTime, LongEndTime = transaction.EndTime.Value.Ticks, ParkingLotId = transaction.ParkingLotId, Status = transaction.Status, TransactionCode = transaction.TransactionCode, TransactionDate = transaction.TransactionDate, }; return(Json(new ResultModel { obj = result, success = true, })); } catch (Exception ex) { return(Json(new ResultModel { success = false, })); } }