public async Task <ActionResult <Expense> > PostExpense(int userId, ExpenseCreationDto expenseCreation) { Console.WriteLine("reached here"); var user = await _repo.GetUser(userId); expenseCreation.SubmitterName = user.UserName; var expense = _mapper.Map <Expense>(expenseCreation); user.Expenses.Add(expense); if (await _repo.SaveAll()) { return(CreatedAtRoute("GetExpense", new { userId = userId, id = expense.Id }, expense)); } throw new Exception("Failed Creating expensing"); }
public async Task <ActionResult <Expense> > PostExpense(int userId, ExpenseCreationDto expenseCreation) { Console.WriteLine("reached here"); var user = await _repo.GetUser(userId); expenseCreation.SubmitterName = user.UserName; var expense = _mapper.Map <Expense>(expenseCreation); user.Expenses.Add(expense); if (await _repo.SaveAll()) { var logRepo = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepo, new FileInfo("log4net.Config")); var logger = LogManager.GetLogger(typeof(ExpensesController)); logger.Info("New Expense Submitted at " + DateTime.Now); return(CreatedAtRoute("GetExpense", new { userId = userId, id = expense.Id }, expense)); } throw new Exception("Failed Creating expensing"); }