// Get all details for a given vsla public VslaDetails vslaInformation(string vslaId) { int id = Convert.ToInt32(vslaId); VslaRepo vslaRepo = new VslaRepo(); DigitizingDataDomain.Model.Vsla vslaData = vslaRepo.FindVslaById(id); if (vslaData != null) { VslaDetails result = new VslaDetails() { VslaId = vslaData.VslaId, VslaCode = vslaData.VslaCode, VslaName = vslaData.VslaName, grpPhoneNumber = vslaData.GroupAccountNumber, PhysicalAddress = vslaData.PhysicalAddress, GpsLocation = vslaData.GpsLocation, DateRegistered = string.IsNullOrEmpty(vslaData.DateRegistered.ToString()) ? "--" : vslaData.DateRegistered.ToString(), DateLinked = string.IsNullOrEmpty(vslaData.DateLinked.ToString()) ? "--" : vslaData.DateLinked.ToString(), RegionName = vslaData.VslaRegion.RegionName, representativeName = vslaData.ContactPerson, representativePosition = vslaData.PositionInVsla, repPhoneNumber = vslaData.PhoneNumber, tTrainerId = vslaData.CBT.Id, tTrainerName = vslaData.CBT.Username, GroupAccountNumber = vslaData.GroupAccountNumber, numberOfCycles = Convert.ToString(vslaData.NumberOfCycles), Implementer = vslaData.Implementer != null ? vslaData.Implementer : "--", RegionId = Convert.ToString(vslaData.VslaRegion.RegionId) }; return(result); } return(null); }
// edit an existing vsla public OperationResult editVsla(Stream jsonStream) { StreamReader reader = new StreamReader(jsonStream); string data = reader.ReadToEnd(); VslaDetails request; OperationResult operationResult = null; VslaRepo vslaRepo = null; try { operationResult = new OperationResult(); vslaRepo = new VslaRepo(); request = JsonConvert.DeserializeObject <VslaDetails>(data); // First check if the vsla exists int _vslaId = Convert.ToInt32(request.VslaId); DigitizingDataDomain.Model.Vsla vslaData = vslaRepo.FindVslaById(_vslaId); if (vslaData != null) { DigitizingDataDomain.Model.Vsla vsla = new DigitizingDataDomain.Model.Vsla(); // NOT NECCESSARY vslaData.VslaName = Convert.ToString(request.VslaName); vslaData.PhoneNumber = Convert.ToString(request.repPhoneNumber); vslaData.ContactPerson = Convert.ToString(request.representativeName); vslaData.VslaPhoneMsisdn = Convert.ToString(request.grpPhoneNumber); vslaData.PositionInVsla = Convert.ToString(request.representativePosition); vslaData.PhysicalAddress = Convert.ToString(request.PhysicalAddress); vslaData.GpsLocation = Convert.ToString(request.GpsLocation); vslaData.GroupAccountNumber = Convert.ToString(request.GroupAccountNumber); vslaData.NumberOfCycles = Convert.ToInt32(request.numberOfCycles); vslaData.Implementer = Convert.ToString(request.Implementer); // region id DigitizingDataDomain.Model.VslaRegion vslaRegion = new DigitizingDataDomain.Model.VslaRegion(); vslaRegion.RegionId = Convert.ToInt32(request.RegionName); vslaData.VslaRegion = vslaRegion; Boolean updateResult = false; if (vslaData.VslaId > 0) { updateResult = vslaRepo.Update(vslaData); if (updateResult) { // if sucessfu, also add the support type addSupportType(_vslaId, request.tTrainerId, request.GroupSupport); // then construct a json feedback operationResult.result = "1"; operationResult.operation = "edit"; operationResult.VslaCode = null; } else { operationResult.result = "-1"; operationResult.operation = null; operationResult.VslaCode = null; } } } } catch (Exception e) { } return(operationResult); }