public async Task <CategoryBoundaryOutput> ExecuteDelete(CategoryBoundaryInput input) { //if (input.Category.IsDefault) { // var category = await this._categoryRepository.GetEntityAsync(e => e.Id == input.Category.Id); // if (category != null) { // switch (input.Category.Type) { // case CategoryTypes.Organization: // ((Organization)category).Parts.Clear(); // break; // case CategoryTypes.Condition: // ((Condition)category).PartInstances.Clear(); // break; // case CategoryTypes.StockType: // var individual=await // var partInstances=((StockType)category).PartInstances; // foreach(var partInstance in partInstances) { // } // break; // case CategoryTypes.Usage: // ((Organization)category).Parts.Clear(); // break; // default: // await this._unitOfWork.Undo(); // return new CategoryBoundaryOutput(null, false, "Internal Error: Invalid category type"); // } // var deleted = await this._categoryRepository.DeleteAsync(org); // } else { // return new CategoryBoundaryOutput(null, false, "Error: Could not find category"); // } //} else { // return new CategoryBoundaryOutput(null, false, "Error: Cannot delete defaul category"); //} return(new CategoryBoundaryOutput(null, false, "Error: Not Implemented")); }
public async Task <CategoryBoundaryOutput> ExecuteAdd(CategoryBoundaryInput input) { var category = input.Category.GetCategory(); if (category == null) { return(new CategoryBoundaryOutput(null, false, "Internal Error: Could not Cast to Specified Category, Please Contact Admin")); } if (input.Category.Type == CategoryTypes.StockType && input.Category.IsDefault) { return(new CategoryBoundaryOutput(null, false, "Error: Cannot change default StockType")); } if (input.IsDefault_Changed) { await this.ClearCategoryDefault(input.Category.Type); } if (input.Category.Type == CategoryTypes.StockType) { CombinedAlert combinedAlert = new CombinedAlert(); combinedAlert.StockHolder = category as StockType; this._context.Add(combinedAlert); } var added = await this._categoryRepository.AddAsync(category); if (added != null) { var count = await this._unitOfWork.Save(); if (count > 0) { return(new CategoryBoundaryOutput(category, true, "Success: Category Added")); } else { await this._unitOfWork.Undo(); return(new CategoryBoundaryOutput(null, false, "Error: Failed to Add new Category")); } } else { await this._unitOfWork.Undo(); return(new CategoryBoundaryOutput(null, false, "Error: Failed to Add new Category")); } }
public async Task <CategoryBoundaryOutput> Execute(CategoryBoundaryInput input) { switch (input.EditAction) { case Boundaries.EditAction.Add: return(await this.ExecuteAdd(input)); case Boundaries.EditAction.Delete: return(await this.ExecuteDelete(input)); case Boundaries.EditAction.Update: return(await this.ExecuteUpdate(input)); default: return(new CategoryBoundaryOutput(null, false, "Error: Invalid Edit Action")); } }
public async Task <CategoryBoundaryOutput> ExecuteUpdate(CategoryBoundaryInput input) { var category = await this._categoryRepository.GetEntityAsync(e => e.Id == input.Category.Id); if (category != null) { if (input.IsDefault_Changed) { await this.ClearCategoryDefault(input.Category.Type); } switch (input.Category.Type) { case CategoryTypes.Organization: case CategoryTypes.Condition: case CategoryTypes.Usage: category.Set(input.Category); break; case CategoryTypes.StockType: category.Set(input.Category); ((StockType)category).Quantity = input.Category.Quantity; ((StockType)category).MinQuantity = input.Category.MinQuantity; ((StockType)category).SafeQuantity = input.Category.SafeQuantity; ((StockType)category).HoldsBubblers = input.Category.HoldsBubblers; break; case CategoryTypes.InvalidType: return(new CategoryBoundaryOutput(null, false, "Error: Invalid Type, Please make sure category type is selected")); default: return(new CategoryBoundaryOutput(null, false, "Internal Error: No Type, Please contact Admin")); } var updated = await this._categoryRepository.UpdateAsync(category); if (updated != null) { var count = await this._unitOfWork.Save(); if (count != 0) { return(new CategoryBoundaryOutput(category, true, "Success: Category Updated")); } else { await this._unitOfWork.Undo(); return(new CategoryBoundaryOutput(null, false, "Error: Save Failed")); } } else { await this._unitOfWork.Undo(); return(new CategoryBoundaryOutput(null, false, "Error: Update Failed")); } } else { return(new CategoryBoundaryOutput(null, false, "Error: Category Not Found,Please Contact Admin")); } }