private static void addItem() { IItemDTO itemDTO = (IItemDTO)DTOFactory.Instance.Create(DTOType.Item, null); itemDTO.ItemName = "itemitemitem"; itemDTO.SubCategotyId = 1; IEcommerceManagerFacade itemManagerFacade = (IEcommerceManagerFacade)FacadeFactory.Instance.Create(FacadeType.EcommerceManager, null); OperationResult <int> operationResult = itemManagerFacade.addItem(itemDTO); 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 AddItem(Item item) { ActionResult retVal = null; if (ModelState.IsValid) { item.SubCategotyId = addItemcategoryId; IEcommerceManagerFacade employeeFacade = (IEcommerceManagerFacade)FacadeFactory.Instance.Create(FacadeType.EcommerceManager); IItemDTO itemDTO = (IItemDTO)DTOFactory.Instance.Create(DTOType.Item); itemDTO.ItemName = item.ItemName; itemDTO.SubCategotyId = item.SubCategotyId; OperationResult <int> result = employeeFacade.addItem(itemDTO); if (result.IsValid()) { retVal = new JsonResult() { Data = "Sucessfully Added", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else if (result.HasValidationFailed() && result.ValidationResult != null) { this.HandleValidationFailure(result); return(AddItem(addItemcategoryId)); } else { OperationResult <int> succes = OperationResult <int> .CreateFailureResult("Item 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); }