private async Task <LocationManagmentOutput> ExecuteUpdate(LocationManagmentInput input) { var location = await this._locationRepository.GetEntityAsync(e => e.Id == input.Location.Id); if (location != null) { //location.Id = input.Location.Id; location.Name = input.Location.Name; location.Description = input.Location.Description; location.IsDefualt = input.Location.IsDefualt; var updated = await this._locationRepository.UpdateAsync(location); if (updated != null) { var count = await this._unitOfWork.Save(); if (count > 0) { return(new LocationManagmentOutput(new LocationDto(updated), true, "Success: Location Updated, Reloading..")); } else { return(new LocationManagmentOutput(null, false, "Internal Error: Error while saving location, please contact admin")); } } else { return(new LocationManagmentOutput(null, false, "Internal Error: Error while updating location, please contact admin")); } } else { return(new LocationManagmentOutput(null, false, "Error: Could not find location to update")); } }
public async Task <LocationManagmentOutput> Execute(LocationManagmentInput input) { switch (input.EditAction) { case Boundaries.EditAction.Add: return(await this.ExecuteAdd(input)); case Boundaries.EditAction.Delete: return(new LocationManagmentOutput(null, false, "Internal Error: Action not supported in this UseCase")); case Boundaries.EditAction.Update: return(await this.ExecuteUpdate(input)); default: return(new LocationManagmentOutput(null, false, "Internal Error: Action not implemented")); } }
private async Task <LocationManagmentOutput> ExecuteAdd(LocationManagmentInput input) { Location location; switch (input.Location.LocationType) { case LocationType.Warehouse: location = new Warehouse(); break; case LocationType.Consumer: location = new Consumer(); break; case LocationType.NotSelected: return(new LocationManagmentOutput(null, false, "Error: Must Select LocationType")); default: return(new LocationManagmentOutput(null, false, "Internal Error: Action not implemented")); } //location.Id = input.Location.Id; location.Name = input.Location.Name; location.Description = input.Location.Description; location.IsDefualt = input.Location.IsDefualt; var added = await this._locationRepository.AddAsync(location); if (added != null) { var count = await this._unitOfWork.Save(); if (count > 0) { return(new LocationManagmentOutput(new LocationDto(added), true, "Success: Location Created, Reloading..")); } else { return(new LocationManagmentOutput(null, false, "Internal Error: Error while saving location, please contact admin")); } } else { return(new LocationManagmentOutput(null, false, "Internal Error: Error while adding location, please contact admin")); } }
public static async Task TestngLocations() { DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>(); //optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); optionsBuilder.UseSqlServer("server=172.20.4.20;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true"); Console.WriteLine("Running..."); using var context = new ManufacturingContext(optionsBuilder.Options); //IRepository<Location> locationRepository = new LocationRepository(context); ILocationManagmentUseCase locationService = new LocationManagmentUseCase(context); var location = await locationService.GetLocation(1); location.Description = "Testing Description using the UseCase"; LocationManagmentInput input = new LocationManagmentInput(location, Application.Boundaries.EditAction.Update); var output = await locationService.Execute(input); if (output.Success) { Console.WriteLine("Should be updated"); } else { Console.WriteLine("Updated Failed:"); } Console.WriteLine(output.Message); Console.ReadKey(); //var location = await locationRepository.GetEntityAsync(e => e.Id == 1); //location.Description = location.Name; //var updated = await locationRepository.UpdateAsync(location); //if (updated != null) { // var count = await context.SaveChangesAsync(); // if (count > 0) { // Console.WriteLine("Saved Successfully"); // } else { // Console.WriteLine("Count was 0"); // } //} else { // Console.WriteLine("Updated Failed"); //} //Console.ReadKey(); }
private async Task <LocationManagmentOutput> ExecuteDelete(LocationManagmentInput input) { var location = await this._locationRepository.GetEntityAsync(e => e.Id == input.Location.Id); if (location != null) { if (!location.IsDefualt) { var deleted = await this._locationRepository.DeleteAsync(location); if (deleted != null) { var count = await this._unitOfWork.Save(); if (count > 0) { return(new LocationManagmentOutput(new LocationDto(deleted), true, "Success: Location Updated, Reloading..")); } else { return(new LocationManagmentOutput(null, false, "Internal Error: Error while saving location, please contact admin")); } } else { return(new LocationManagmentOutput(null, false, "Internal Error: Error while updating location, please contact admin")); } } else { return(new LocationManagmentOutput(null, false, "Error: Cannot delete default location, please change default location then try again")); } } else { return(new LocationManagmentOutput(null, false, "Error: Could not find location to update")); } }