func (ctrl controller) CreateActivity(context *admin.Context) { result, err := context.FindOne() activityResource := ctrl.ActivityResource newActivity := &QorActivity{} if err == nil { if context.AddError(activityResource.Decode(context.Context, newActivity)); !context.HasError() { context.AddError(CreateActivity(context, newActivity, result)) } } context.AddError(err) redirectTo := context.Request.Referer() if context.HasError() { responder.With("html", func() { context.Flash(context.Error(), "error") http.Redirect(context.Writer, context.Request, redirectTo, http.StatusFound) }).With("json", func() { context.JSON("edit", map[string]interface{}{"errors": context.GetErrors()}) }).Respond(context.Request) } else { responder.With("html", func() { context.Flash(string(context.Admin.T(context.Context, "activity.successfully_created", "Activity was successfully created")), "success") http.Redirect(context.Writer, context.Request, redirectTo, http.StatusFound) }).With("json", func() { context.Resource = activityResource context.JSON("show", newActivity) }).Respond(context.Request) } }