public HttpResponseMessage DeleteEntitiy(CompanyChartViewModel CompanyChart)
 {
     if (ModelState.IsValid)
     {
         SetViewModel(CompanyChart);
         var deleteAccount = _companyChartService.Delete(CompanyChart.GetModel());
         return(Request.CreateResponse(HttpStatusCode.OK, CompanyChart));
     }
     return(Request.CreateResponse(HttpStatusCode.NotFound));
 }
        public HttpResponseMessage PostEntitiy(CompanyChartViewModel CompanyChart)
        {
            if (ModelState.IsValid)
            {
                var account = _companyChartService.Create(CompanyChart.Model);
                CompanyChart.SetModel(account);
                return(Request.CreateResponse(HttpStatusCode.OK, CompanyChart));
            }


            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));
        }
        public HttpResponseMessage PutEntitiy(CompanyChartViewModel CompanyChart)
        {
            if (ModelState.IsValid)
            {
                SetViewModel(CompanyChart);

                var updatedAccount = _companyChartService.Update(CompanyChart.GetModel());

                return(Request.CreateResponse(HttpStatusCode.OK, CompanyChart));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        private void SetViewModel(CompanyChartViewModel viewModel)
        {
            var foundEntity = _companyChartService.Find(viewModel.Id);

            //Id = CompanyChart.Id,
            //        Title = CompanyChart.Title,
            //        HasChildren = CompanyChart.ChildCompanyChart.Any(),
            //        ParentId = CompanyChart.ParentId,

            foundEntity.Id       = viewModel.Id;
            foundEntity.Title    = viewModel.Title;
            foundEntity.ParentId = viewModel.ParentId;

            viewModel.SetModel(foundEntity);
        }