public BaseResult SaveMonthlyPlanAsTemplate(int?MonthlyPlanId, string TemplateName) { BaseResult Result = new OperationResult(); MonthlyBudget budget = null; budget = GetMonthlyBudget(MonthlyPlanId.Value); if (budget != null) { string templateJson = string.Empty; try { var serializer = new JavaScriptSerializer(); templateJson = serializer.Serialize(budget); } catch (Exception Ex) { Result = new OperationResult(ResultStatus.Exception, Reflection.GetCurrentMethodName()) { Message = "Unable to build JSON template from monthly plan", Value = Ex }; } if (string.IsNullOrEmpty(templateJson) == false) { // info log _log.InfoFormat("Generated Template: {0}", templateJson); // save MonthlyPlanTemplate template = new MonthlyPlanTemplate() { EntityState = EntityState.Added, Id = 0, TemplateName = TemplateName, Template = templateJson }; bool result = false; try { result = DefaultAddEntity(template); if (result) { Result = new OperationResult(ResultStatus.Success, Reflection.GetCurrentMethodName()); } else { Result = new OperationResult(ResultStatus.Failure, Reflection.GetCurrentMethodName()); } } catch (Exception Ex) { Result = new OperationResult(ResultStatus.Exception, Reflection.GetCurrentMethodName()) { Message = "Unable to save monthly plan template", Value = Ex }; } } } else { Result = new OperationResult(ResultStatus.Failure, Reflection.GetCurrentMethodName()) { Message = string.Format("Unable to create template based on monthly pland id {0}, the template was not found in the database.", MonthlyPlanId), Value = HttpStatusCode.NoContent }; } return(Result); }