void ValidateViewModel(ComponentCNDViewModel model)
        {
            if ((model.ComponentId > 0 && model.Id == 0) ||
                (model.ComponentId == 0 && model.Id > 0))
            {
                throw new ArgumentException("Data inconsistency when creating / updating component");
            }

            if (model.ResultsMatrixId <= 0)
            {
                throw new ArgumentException("Component not related to a results matrix");
            }

            if (model.Statement == null)
            {
                throw new ArgumentException("Statement must be specified");
            }

            if (model.OrderNumber == null || model.OrderNumber <= 0)
            {
                throw new ArgumentException("Order number must be specified");
            }

            if (model.ExpectedResults == null)
            {
                throw new ArgumentException("Expected results must be specified");
            }

            const int MAX_EXPECTED_RESULTS_LENGTH = 500;

            if (model.ExpectedResults.Length > MAX_EXPECTED_RESULTS_LENGTH)
            {
                throw new ArgumentException("Expected results too long");
            }

            if (model.Contact == null)
            {
                throw new ArgumentException("Contact must be specified");
            }

            if (model.Specialist == null)
            {
                throw new ArgumentException("Specialist must be specified");
            }

            if (model.StartDate == DateTime.MinValue)
            {
                throw new ArgumentException("Start date must be specified");
            }

            if (model.EndDate == DateTime.MinValue)
            {
                throw new ArgumentException("End date must be specified");
            }
        }
        public virtual ActionResult SaveComponentCND(ComponentCNDViewModel model)
        {
            var response = new ResponseBase();

            try
            {
                ValidateViewModel(model);

                response = _componentCNDService.SaveComponent(model);
            }
            catch (ArgumentException e)
            {
                Logger.GetLogger().WriteError(
                    "ComponentCNDController", "Error validating the model", e);

                response.IsValid      = false;
                response.ErrorMessage = e.Message;
            }

            return(new JsonResult {
                Data = response
            });
        }