public IResult UpdateLocation(IUpdateLocationParameters parameters) { var parameterResult = parameters.ToParsedParameters(); if (!parameterResult.Success) { return(parameterResult); } var employeeResult = new GetEmployeeCommand(_facilityUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <string>()); } var result = new UpdateLocationCommand(_facilityUnitOfWork).UpdateLocation(parameterResult.ResultingObject); if (!result.Success) { return(result); } _facilityUnitOfWork.Commit(); return(SyncParameters.Using(new SuccessResult(), new SyncLocationsParameters { EmployeeKey = employeeResult.ResultingObject, Locations = new List <ILocationKey> { parameterResult.ResultingObject.LocationKey } })); }
public IActionResult UpdateLocation([FromBody] LocationDto locationDto) { EnsureArg.IsNotNull(locationDto); var command = new UpdateLocationCommand(locationDto); CommandDispatcher.Execute(command); return(NoContent()); }
public async Task <APIResult> UpdateLocation([FromBody] UpdateLocationCommand command) { var rs = await mediator.Send(command); return(new APIResult() { Result = rs }); }
public async void LocationShouldThrowNotFoundException() { var updatedLocation = new UpdateLocationCommand { Id = GConst.InvalidId, Name = GConst.ValidName }; var status = await Record.ExceptionAsync(async() => await sut.Handle(updatedLocation, CancellationToken.None)); Assert.NotNull(status); Assert.Equal(string.Format(GConst.NotFoundExceptionMessage, GConst.Location, GConst.InvalidId), status.Message); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateLocationCommand command) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var response = await this._mediator.Send(command); return(this.Ok()); }
public async Task <ActionResult> Update(int LocationId, UpdateLocationCommand command) { if (LocationId != command.LocationId) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public async Task LocationNotExist_Exception() { var command = new UpdateLocationCommand { LocationId = 2, Name = "abc", Description = "abc" }; Task Act() => _handler.Handle(command, CancellationToken.None); var ex = await Record.ExceptionAsync(Act) as EntityNotFoundException <Location>; Assert.NotNull(ex); Assert.Equal(2, ex.EntityId); }
public IActionResult Put(int id, [FromBody] UpdateLocationModel updateModel) { var updateCommand = new UpdateLocationCommand() { LocationId = id }; _mapper.Map <UpdateLocationModel, UpdateLocationCommand>(updateModel, updateCommand); var result = _locationService.UpdateLocation(updateCommand); return(CreateResponse <Location, LocationModel>(result)); }
public async void LocationShouldThrowReferenceExceptionForInvalidAddress() { var updatedLocation = new UpdateLocationCommand { Id = locationId, Name = GConst.ValidName, ClientId = clientId, AddressId = GConst.InvalidId }; var status = await Record.ExceptionAsync(async() => await sut.Handle(updatedLocation, CancellationToken.None)); Assert.NotNull(status); Assert.Equal(string.Format(GConst.ReferenceExceptionMessage, GConst.Update, GConst.Location, locationId, GConst.AddressLower, GConst.InvalidId), status.Message); }
public async Task Ok() { var newName = "testName"; var newDescription = "testDescription"; var command = new UpdateLocationCommand { LocationId = 1, Name = newName, Description = newDescription }; var result = await _handler.Handle(command, CancellationToken.None); Assert.NotNull(result); Assert.StrictEqual(_location, result); Assert.Equal(result.Name, newName); Assert.Equal(result.Description, newDescription); }
public IActionResult Put(int id, [FromBody] UpdateLocationModel updateModel) { var updateCommand = new UpdateLocationCommand() { LocationId = id }; this.mapper.Map <UpdateLocationModel, UpdateLocationCommand>(updateModel, updateCommand); Location location = this.locationService.UpdateLocation(updateCommand); var model = this.mapper.Map <Location, LocationModel>(location); return(this.Ok(model)); }
public async override void OnNavigatedTo(NavigationParameters parameters) { base.OnNavigatedTo(parameters); if (parameters.GetNavigationMode() == NavigationMode.New) { if (parameters.ContainsKey("Id")) { IsBusy = true; try { Report = await ReportManager.DefaultManager.LookupAsync((string)parameters["Id"]); this.IsEdit = report.RefUserId == GlobalAttributes.User.Id; if (Report.ReportLat != 0 && Report.ReportLon != 0) { GpsImage = "ic_gps_on.png"; } // get reportGroup //var reportGroupItems = await CustomFunction.Get<List<GroupItem>>($"api/values/groupsbyreport/{Report.Id}"); var reportGroupItems = await ReportGroupManager.DefaultManager.GetGroupsByReport(Report.Id); if (reportGroupItems.Any()) { this.groupIds = string.Join(",", reportGroupItems.Select(x => x.Id)); this.GroupLabel = string.Join(",", reportGroupItems.Select(x => x.GroupName)); } } catch (Exception e) { Models.DebugUtil.WriteLine("DetailReportViewModel > " + e.Message); } IsBusy = false; if (Report != null) { UpdateLocationCommand.Execute(); Report.PropertyChanged += OnDateTimeChanged; } } else { await dialogService.DisplayAlertAsync("Error", "Failed to load the detail page!", "OK"); await navigationService.GoBackAsync(); } } }
public async Task UpdateLocation_Call() { //-------------- Arrange ------------- CommonArrangements(); var request = new UpdateLocationRequest(); var command = new UpdateLocationCommand(); A.CallTo(() => mapper.Map <UpdateLocationRequest, UpdateLocationCommand>(request)).Returns(command); //-------------- Act ------------- var resp = locationService.UpdateLocationAsync(request); //-------------- Assert ------------- A.CallTo(() => bus.SendAsync(command)).MustHaveHappened(Repeated.Exactly.Once); }
public async Task InvalidCommand_Exception(int nameLength, int descriptionLength) { if (nameLength < 0 || descriptionLength < 0) { return; } var name = new string('x', nameLength); var description = new string('x', descriptionLength); var validator = new UpdateLocationCommandValidator(); var command = new UpdateLocationCommand { Name = name, Description = description }; var result = await validator.ValidateAsync(command); Assert.NotNull(result); Assert.False(result.IsValid); }
public async void LocationShouldUpdateCorrect() { var updatedLocation = new UpdateLocationCommand { Id = locationId, Name = GConst.ValidName, StartDay = GConst.ValidStartDay, EndDay = GConst.ValidEndDay, ClientId = clientId, AddressId = addressId }; var status = Task <Unit> .FromResult(await sut.Handle(updatedLocation, CancellationToken.None)); var resultId = context.Locations.SingleOrDefault(x => x.Name == GConst.ValidName).Id; Assert.Equal(locationId, resultId); Assert.Equal(GConst.SuccessStatus, status.Status.ToString()); Assert.Equal(GConst.ValidCount, context.Locations.Count()); }
public Result <Location> UpdateLocation(UpdateLocationCommand updateLocationCommand) { Location location = _locationRepository.GetLocation(updateLocationCommand.LocationId); if (location == null) { return(Result.Failure <Location>($"No location was found with the id {updateLocationCommand.LocationId}")); } // Update the properties location.Name = updateLocationCommand.Name; location.StreetAddress = updateLocationCommand.StreetAddress; location.City = updateLocationCommand.City; location.State = updateLocationCommand.State; location.ZipCode = updateLocationCommand.ZipCode; _locationRepository.Save(location); UnitOfWork.SaveChanges(); return(Result.Success <Location>(location)); }
public Location UpdateLocation(UpdateLocationCommand updateLocationCommand) { Location location = _locationRepository.GetLocation(updateLocationCommand.LocationId); if (location == null) { throw new ObjectNotFoundException($"No location was found with the id {updateLocationCommand.LocationId}"); } // Update the properties location.Name = updateLocationCommand.Name; location.StreetAddress = updateLocationCommand.StreetAddress; location.City = updateLocationCommand.City; location.State = updateLocationCommand.State; location.ZipCode = updateLocationCommand.ZipCode; _locationRepository.Save(location); UnitOfWork.SaveChanges(); return(location); }
public async Task <ActionResult> Update([FromForm] UpdateLocationCommand command) { await Mediator.Send(command); return(NoContent()); }
public async Task <ActionResult> UpdateLocation( int id, UpdateLocationCommand commmand) => await this.Send(commmand.SetId(id));
public UpdateLocationCommandValidatorTests() { this.updateValidator = new UpdateLocationCommandValidator(); this.updateCommand = new UpdateLocationCommand(); }
public async Task <ActionResult <Location> > UpdateLocation(UpdateLocationCommand command) { return(await Mediator.Send(command)); }