public static Result newTask() { Form<Task> filledForm = taskForm.bindFromRequest(); if (filledForm.hasErrors()) { return badRequest(views.html.index.render(Task.all(), filledForm)); } else { Task.create(filledForm.get()); return redirect(routes.Application.tasks()); } }
public static Result newTask() { User user = loadUser(); Form<Task> filledForm = taskForm.bindFromRequest(); if (filledForm.hasErrors()) { flash("error", "The task could not be saved."); return badRequest(main.render("Tasks", null, tasks.render(user.tasks, filledForm))); } else { Task task = filledForm.get(); task.owner = user; task.save(); return created(main.render("Tasks", null, tasks.render(user.tasks, taskForm))); } }
public static Result createNewUser() { Form<User> nu = userForm.bindFromRequest(); ObjectNode jsonData = Json.newObject(); String userName = null; try { userName = nu.field("firstName").value() + " " + (nu.field("middleInitial")).value() + " " + (nu.field("lastName")).value(); jsonData.put("userName", userName); jsonData.put("firstName", nu.get().getFirstName()); jsonData.put("middleInitial", nu.get().getMiddleInitial()); jsonData.put("lastName", nu.get().getLastName()); jsonData.put("password", nu.get().getPassword()); jsonData.put("affiliation", nu.get().getAffiliation()); jsonData.put("title", nu.get().getTitle()); jsonData.put("email", nu.get().getEmail()); jsonData.put("mailingAddress", nu.get().getMailingAddress()); jsonData.put("phoneNumber", nu.get().getPhoneNumber()); jsonData.put("faxNumber", nu.get().getFaxNumber()); jsonData.put("researchFields", nu.get().getResearchFields()); jsonData.put("highestDegree", nu.get().getHighestDegree()); JsonNode response = RESTfulCalls.postAPI( Constants.URL_HOST + Constants.CMU_BACKEND_PORT + Constants.ADD_USER, jsonData); // flash the response message Application.flashMsg(response); return redirect(routes.Application.createSuccess()); } catch (IllegalStateException e) { e.printStackTrace(); Application.flashMsg(RESTfulCalls.createResponse(ResponseType.CONVERSIONERROR)); } catch (Exception e) { e.printStackTrace(); Application.flashMsg(RESTfulCalls.createResponse(ResponseType.UNKNOWN)); } return ok(signup.render(nu)); }