public async Task <IActionResult> GetShelfLocation(ShelfLocationParametersModel parameters) { if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit) { return(await Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter")); } if (parameters.Page < Configurations.DefaultPageValue) { return(await Error(HttpStatusCode.BadRequest, "page", "Invalid request parameters")); } var shelfLocationDto = _shelfLocationApiService.GetShelfLocation( parameters.Ids, parameters.Limit, parameters.Page, parameters.SinceId, parameters.CreatedAtMin, parameters.CreatedAtMax) .Select(trans => trans.ToDto()).ToList(); var rootObject = new ShelfLocationRootObject { ShelfLocation = shelfLocationDto }; var json = JsonFieldsSerializer.Serialize(rootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> CreateShelfLocation([ModelBinder(typeof(JsonModelBinder <ShelfLocationDto>))] Delta <ShelfLocationDto> shelfLocationDelta) { if (!ModelState.IsValid) { return(await Error()); } var newShelfLocation = new ShelfLocation(); shelfLocationDelta.Merge(newShelfLocation); await _shelfLocationRepository.InsertAsync(newShelfLocation); await UserActivityService.InsertActivityAsync("AddNewShelfLocation", $"Added a new shelf location (ID = {newShelfLocation.Id})", newShelfLocation); var newShelfLocationDto = newShelfLocation.ToDto(); var rootObject = new ShelfLocationRootObject(); rootObject.ShelfLocation.Add(newShelfLocationDto); var json = JsonFieldsSerializer.Serialize(rootObject, string.Empty); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> UpdateShelfLocation([ModelBinder(typeof(JsonModelBinder <ShelfLocationDto>))] Delta <ShelfLocationDto> shelfLocationDelta) { if (!ModelState.IsValid) { return(await Error()); } var currentShelfLocation = _shelfLocationApiService.GetShelfLocationById(shelfLocationDelta.Dto.Id); if (currentShelfLocation == null) { return(await Error(HttpStatusCode.NotFound, "shelf_location", "not found")); } shelfLocationDelta.Merge(currentShelfLocation); await _shelfLocationRepository.UpdateAsync(currentShelfLocation); await UserActivityService.InsertActivityAsync("EditShelfLocation", $"Edited a shelf location (ID = {currentShelfLocation.Id})", currentShelfLocation); var shelfLocationDto = currentShelfLocation.ToDto(); var rootObject = new ShelfLocationRootObject(); rootObject.ShelfLocation.Add(shelfLocationDto); var json = JsonFieldsSerializer.Serialize(rootObject, string.Empty); return(new RawJsonActionResult(json)); }
protected async Task <IActionResult> RootObjectResult(IList <ShelfLocationDto> entities, string fields) { var rootObj = new ShelfLocationRootObject { ShelfLocation = entities }; var json = JsonFieldsSerializer.Serialize(rootObj, fields); return(await Task.FromResult <IActionResult>(new RawJsonActionResult(json))); }
public async Task <IActionResult> GetShelfLocationById(int id, string fields = "") { if (id <= 0) { return(await Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var shelfLocation = _shelfLocationApiService.GetShelfLocationById(id); if (shelfLocation == null) { return(await Error(HttpStatusCode.NotFound, "shelf_location", "not found")); } var rootObject = new ShelfLocationRootObject(); rootObject.ShelfLocation.Add(shelfLocation.ToDto()); var json = JsonFieldsSerializer.Serialize(rootObject, fields); return(new RawJsonActionResult(json)); }