'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
  errorHandler = require('./errors.server.controller'),
  Category = mongoose.model('Category'),
   _ = require('lodash');

/**
 * Create a Category
 */
exports.create = function(req, res) {

  var category = new Category(req.body);

  category.save(function(err) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      res.status(201).json(category);
    }
  });

};

/**
 * Show the current Category
 */
exports.read = function(req, res) {

  Category.findById(req.params.categoryId).exec(function(err, category) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      if (!category) {
        return res.status(404).send({
          message: 'Category not found'
        });
      }
      res.json(category);
    }
  });

};

/**
 * Update a Category
 */
exports.update = function(req, res) {

};

/**
 * Delete an Category
 */
exports.delete = function(req, res) {

};

/**
 * List of Categories
 */
exports.list = function(req, res) {

  Category.find().exec(function (err, categories) {
    if (err){
      return res.status(400).send({
          message: errorHandler.getErrorMessage(err)
        });
    } else {
      res.json(categories);
    }
  });

};

@@ -1019,32 +1019,306 @@
 on(req, res) %7B%0A%0A
+  var category = req.category;%0A%0A  category = _.extend(category, req.body);%0A%0A  category.save(function(err) %7B%0A    if (err) %7B%0A      return res.status(400).send(%7B%0A        message: errorHandler.getErrorMessage(err)%0A      %7D);%0A    %7D else %7B%0A      res.json(category);%0A    %7D%0A  %7D);%0A  %0A
 %7D;%0A%0A/**%0A * Delet

Modify Category controller for Update.