public async Task <IActionResult> Post([FromBody] AddUpdatePersonLocationCommand registerpersonlocationcommand) { var response = await _mediator.Send(registerpersonlocationcommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }
public async Task <Result <AddUpdatePersonLocationResponse> > Handle(AddUpdatePersonLocationCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { PersonLocation location = new PersonLocation(); PersonLocationService personLocationService = new PersonLocationService(_unitOfWork); List <PersonLocation> personLocationList = await personLocationService.GetPersonLocation(request.PersonId); if (personLocationList.Count > 0) { personLocationList[0].County = request.CountyId; personLocationList[0].SubCounty = request.SubCountyId; personLocationList[0].Ward = request.WardId; personLocationList[0].NearestHealthCentre = request.NearestHealthCentre; personLocationList[0].LandMark = request.LandMark; location = await personLocationService.UpdatePersonLocation(personLocationList[0]); } else { PersonLocation personLocation = new PersonLocation() { PersonId = request.PersonId, County = request.CountyId, SubCounty = request.SubCountyId, Ward = request.WardId, NearestHealthCentre = request.NearestHealthCentre, LandMark = request.LandMark, Village = "", Location = "", SubLocation = "", Active = false, DeleteFlag = false, CreateDate = DateTime.Now, CreatedBy = request.UserId }; location = await personLocationService.AddPersonLocation(personLocation); } return(Result <AddUpdatePersonLocationResponse> .Valid(new AddUpdatePersonLocationResponse() { Message = "Successful", PersonLocationId = location.Id })); } catch (Exception e) { return(Result <AddUpdatePersonLocationResponse> .Invalid(e.Message)); } } }
public async Task <Result <AddUpdatePersonLocationResponse> > Handle(AddUpdatePersonLocationCommand request, CancellationToken cancellationToken) { try { var PersonLocation = new PersonLocationManager(); if (request.PersonId > 0) { var currentLocation = PersonLocation.GetCurrentPersonLocation(request.PersonId); if (currentLocation.Count > 0) { currentLocation[0].DeleteFlag = true; PersonLocation.UpdatePersonLocation(currentLocation[0]); //public int AddPersonLocation(int personId, int county, int subcounty, int ward, string village, string location, string sublocation, string landmark, string nearesthealthcentre, int userId) res = await Task.Run(() => PersonLocation.AddPersonLocation(request.PersonId, request.CountyId, request.SubCountyId, request.WardId, "", "", "", request.LandMark, request.NearestHealthCentre, request.UserId)); if (res > 0) { msg += "Person Location Successfully Updated"; } } else { res = await Task.Run(() => PersonLocation.AddPersonLocation(request.PersonId, request.CountyId, request.SubCountyId, request.WardId, "", "", "", request.LandMark, request.NearestHealthCentre, request.UserId)); if (res > 0) { msg += "Person Location Successfully Added"; } } } else { msg += "The current person was not updated"; } return(Result <AddUpdatePersonLocationResponse> .Valid(new AddUpdatePersonLocationResponse() { Message = msg })); } catch (Exception e) { return(Result <AddUpdatePersonLocationResponse> .Invalid(e.Message)); } }
public async Task <Result <AddUpdatePersonLocationResponse> > Handle(AddUpdatePersonLocationCommand request, CancellationToken cancellationToken) { try { RegisterPersonService rs = new RegisterPersonService(_unitOfWork); if (request.PersonId > 0) { var currentlocation = await rs.GetCurrentPersonLocation(request.PersonId); if (currentlocation != null) { currentlocation.PersonId = request.PersonId; currentlocation.County = request.CountyId; currentlocation.SubCounty = request.SubCountyId; currentlocation.Ward = request.WardId; currentlocation.LandMark = request.LandMark; currentlocation.NearestHealthCentre = request.NearestHealthCentre; currentlocation.CreatedBy = request.UserId; res = await rs.UpdatePersonLocation(currentlocation); if (res > 0) { msg += "Person Location Successfully Updated"; } } else { res = await Task.Run(() => rs.AddPersonLocation(request.PersonId, request.CountyId, request.SubCountyId, request.WardId, "", "", "", request.LandMark, request.NearestHealthCentre, request.UserId)); if (res > 0) { msg += "Person Location Successfully Added"; } } } return(Result <AddUpdatePersonLocationResponse> .Valid(new AddUpdatePersonLocationResponse() { Message = msg } )); } catch (Exception e) { return(Result <AddUpdatePersonLocationResponse> .Invalid(e.Message)); } }