private static void addSubCategory() { ISubCategoriesDTO subCategoryDTO = (ISubCategoriesDTO)DTOFactory.Instance.Create(DTOType.SubCategory, null); subCategoryDTO.SubCategoryName = "apple"; subCategoryDTO.CategotyId = 2; IEcommerceManagerFacade subCategoryManagerFacade = (IEcommerceManagerFacade)FacadeFactory.Instance.Create(FacadeType.EcommerceManager, null); OperationResult <int> operationResult = subCategoryManagerFacade.addSubCategory(subCategoryDTO); if (operationResult.IsValid()) { System.Console.WriteLine(operationResult.Data); } else if (operationResult.HasValidationFailed() && operationResult.ValidationResult != null) { foreach (EmployeePortalValidationFailure error in operationResult.ValidationResult.Errors) { System.Console.WriteLine(error.PropertyName + " " + error.ErrorMessage); } } else if (operationResult.Message != String.Empty && operationResult.StackTrace != String.Empty) { System.Console.WriteLine(operationResult.Message + " " + operationResult.StackTrace); } }
public ActionResult InsertSubCategory(SubCategory sub) { ActionResult retVal = null; if (ModelState.IsValid) { sub.CategotyId = addcategoryId; IEcommerceManagerFacade employeeFacade = (IEcommerceManagerFacade)FacadeFactory.Instance.Create(FacadeType.EcommerceManager); ISubCategoriesDTO subDTO = (ISubCategoriesDTO)DTOFactory.Instance.Create(DTOType.SubCategory); subDTO.SubCategoryName = sub.SubCategoryName; subDTO.CategotyId = sub.CategotyId; OperationResult <int> result = employeeFacade.addSubCategory(subDTO); if (result.IsValid()) { retVal = new JsonResult() { Data = "Sucessfully Added", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else if (result.HasValidationFailed() && result.ValidationResult != null) { this.HandleValidationFailure(result); return(InsertSubCategory(addcategoryId)); } else { OperationResult <int> succes = OperationResult <int> .CreateFailureResult("SubCategory can't be added. Please try after sometime."); succes.IsValid(); retVal = new JsonResult() { Data = succes }; } } else { retVal = new JsonResult() { Data = "Not Added", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } return(retVal); }