Пример #1
0
		public JsonResult Update(Node node)
		{
			if (ModelState.IsValid)
			{
				var operation = node.Operation;

				var getResult = _operationProvider.GetById(operation.Id);

				if (!getResult.Success || getResult.Result == null)
				{
					Response.StatusCode = (int)HttpStatusCode.BadRequest;
					return Json(getResult.ErrorMessage);
				}

				operation.Type = getResult.Result.Type;

				var updateResult = _operationProvider.Update(operation);

				if (!updateResult.Success)
				{
					Response.StatusCode = (int)HttpStatusCode.BadRequest;
					return Json(updateResult.ErrorMessage);
				}
				return Json(new Node(operation));
			}
			Response.StatusCode = (int)HttpStatusCode.BadRequest;
			return Json(ModelState.ToString());
		}
Пример #2
0
		public JsonResult Add(Node node)
		{
			if (ModelState.IsValid)
			{
				var operation = node.Operation;

				if (operation.GroupId > 0)
				{
					var parentResult = _operationProvider.GetById(operation.GroupId ?? 0);

					if (!parentResult.Success || parentResult.Result == null)
					{
						Response.StatusCode = (int)HttpStatusCode.BadRequest;
						return Json(parentResult.ErrorMessage);
					}
					operation.Level = parentResult.Result.Level + 1;
				}

				var maxOrderResult = _operationProvider.MaxOrder(operation.GroupId ?? 0);

				if (maxOrderResult.Success)
				{
					operation.Order = maxOrderResult.Result;
				}

				var result = _operationProvider.Add(operation);

				if (!result.Success)
				{
					Response.StatusCode = (int)HttpStatusCode.BadRequest;
					return Json(result.ErrorMessage);
				}
				return Json(new Node(operation));
			}
			Response.StatusCode = (int)HttpStatusCode.BadRequest;
			return Json(ModelState.ToString());
		}