Exemplo n.º 1
0
        public IActionResult Put([FromBody] ExpenseViewModel model)
        {
            //TODO
            //Якщо model = null поверни помилку сервера
            if (model == null)
            {
                return(StatusCode(500, new InternalServerError("Model is null")));
            }
            Expense expense = new Expense();

            expense.Cost             = model.Cost;
            expense.Id               = Guid.NewGuid().ToString();
            expense.Name             = model.Name;
            expense.IsComing         = model.IsComing;
            expense.UserId           = _context.Users.Where(p => p.UserName == "Admin").FirstOrDefault().Id;
            expense.CreatedDate      = DateTime.Now;
            expense.LastModifiedDate = expense.CreatedDate;


            _context.Add(expense);
            _context.SaveChanges();
            return(new JsonResult(expense.Adapt <ExpenseViewModel>(), _settings));
        }