public IActionResult AddRecord(string name, string email, string phone, string date, string time, int service_id) { ServiceOutput service = dbService.GetServiceById(service_id); string address = service.Address; int recordId; try { List <User> users = dbService.GetUsersByEmailAndPhone(email, phone); if (users.Count > 0) { recordId = dbService.AddRecord(users[0].Id, service_id, address, time, date); } else { int id = dbService.AddUser(name, email, phone); recordId = dbService.AddRecord(id, service_id, address, time, date); } Console.WriteLine(recordId); return(Json(new { result = "success", record_id = recordId.ToString() })); } catch (Exception) { return(Json(new { result = "failed" })); } }