Last active
October 19, 2015 06:43
-
-
Save SinghHars/b5bbca636d85eb610a7d to your computer and use it in GitHub Desktop.
Create operation using UmbracoApiController :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="umb-dialog-body with-footer"> | |
<div class="umb-pane"> | |
<h5><localize key="create_createUnder">Create Template under </localize> {{currentNode.name}}</h5> | |
<ul class="umb-actions umb-actions-child"> | |
<li> | |
<a href="#/Templates/TemplateTree/new/true" ng-click="nav.hideNavigation()"> | |
<i class="icon-document"></i> | |
<span class="menu-label"> | |
New custom item{{currentNode.name}} | |
<small>Click here to create template under {{currentNode.name}} </small> | |
</span> | |
</a> | |
</li> | |
</ul> | |
</div> | |
</div> | |
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar"> | |
<button class="btn" ng-click="nav.hideDialog()"> | |
<localize key="buttons_somethingElse">Do something else</localize> | |
</button> | |
</div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("umbraco").controller('CreateCtrl', | |
function($scope, $http, $location, $rootScope) { | |
debugger; | |
$scope.action = "save"; | |
$scope.saving = false; | |
$rootScope.alert = false; | |
$scope.save = function() { | |
$scope.saving = true; | |
$http({ method: 'POST', url: '/umbraco/api/StatusApi/PostStatus/', params: { parent: 1 }, data: $scope.status }) | |
.success(function(data) { | |
$rootScope.alert = true; | |
$rootScope.alertMessage = "New status added"; | |
$scope.saving = false; | |
$location.path('/list'); | |
}) | |
.error(function() { | |
$scope.error = "An Error has occured while submitting!"; | |
$scope.saving = false; | |
}); | |
} | |
}); | |
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="umb-panel" ng-controller="CreateCtrl"> | |
<div class="umb-panel-header"> | |
<div class="row-fluid"> | |
<div class="span12"> | |
<h1><span class="icon-documents"></span> Email Template</h1> | |
</div> | |
</div> | |
</div> | |
<div class="umb-panel-body"> | |
<form name="createForm" class="form-horizontal"> | |
<br> | |
<!-- control for subject--> | |
<div class="control-group"> | |
<label for="title" class="control-label">Title</label> | |
<div class="controls"> | |
<input class="span5" id="title" type="text" ng-model="status.Title" | |
required> | |
</div> | |
</div> | |
<!-- control for Body--> | |
<div class="control-group"> | |
<label for="message" class="control-label">Body</label> | |
<div class="controls"> | |
<textarea class="span5" id="message" ng-model="status.Message" rows="4" | |
required></textarea> | |
</div> | |
</div> | |
<div class="form-actions"> | |
<a href="#/Templates" class="btn">Cancel</a> | |
<button id="Email_Save" ng-click="save()" ng-disabled="isClean() || createForm.$invalid || saving" | |
class="btn btn-primary">Save</button> | |
</div> | |
</form> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Web.WebApi; | |
using Adweb_OTL.StatusModel; | |
using Umbraco.Core.Models; | |
using System.Web.Http; | |
using Umbraco.Web.Mvc; | |
namespace Adweb_OTL | |
{ | |
public class StatusApiController : UmbracoApiController | |
{ | |
//Url route | |
//umbraco/api/StatusApi/function_name | |
private const string contentTypeAlias = "Status"; | |
private const string MessagePropertyAlias = "message"; | |
//Creates a new status document under the specified parent | |
[HttpPost] | |
public Status PostStatus(Status status,int parentId) | |
{ | |
System.Diagnostics.Debugger.Launch(); | |
var cs = Services.ContentService; | |
var content = cs.CreateContent(status.Title, parentId, contentTypeAlias); | |
content.Name = status.Title; | |
content.SetValue(MessagePropertyAlias, status.Message); | |
cs.SaveAndPublishWithStatus(content); | |
status.Id = content.Id; | |
return status; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment