// add a new vsla
        public OperationResult addNewVsla(Stream jsonStream)
        {
            StreamReader    reader = new StreamReader(jsonStream);
            string          data   = reader.ReadToEnd();
            VslaDetails     request;
            String          _vslaCode       = string.Empty;
            OperationResult operationResult = null;

            try
            {
                operationResult = new OperationResult();
                _vslaCode       = genVslaCode();
                request         = JsonConvert.DeserializeObject <VslaDetails>(data);
                DigitizingDataDomain.Model.Vsla vsla = new DigitizingDataDomain.Model.Vsla();
                vsla.VslaName           = Convert.ToString(request.VslaName);
                vsla.VslaCode           = Convert.ToString(_vslaCode);
                vsla.PhoneNumber        = Convert.ToString(request.repPhoneNumber);
                vsla.ContactPerson      = Convert.ToString(request.representativeName);
                vsla.VslaPhoneMsisdn    = Convert.ToString(request.grpPhoneNumber);
                vsla.PositionInVsla     = Convert.ToString(request.representativePosition);
                vsla.DateRegistered     = DateTime.Now;
                vsla.DateLinked         = DateTime.Now;
                vsla.PhysicalAddress    = Convert.ToString(request.PhysicalAddress);
                vsla.GpsLocation        = Convert.ToString(request.GpsLocation);
                vsla.GroupAccountNumber = Convert.ToString(request.GroupAccountNumber);
                vsla.Status             = 1;
                vsla.NumberOfCycles     = Convert.ToInt32(request.numberOfCycles);
                vsla.Implementer        = Convert.ToString(request.Implementer);
                // cbt
                DigitizingDataDomain.Model.TechnicalTrainer cbt = new DigitizingDataDomain.Model.TechnicalTrainer();
                cbt.Id   = Convert.ToInt32(request.tTrainerId);
                vsla.CBT = cbt;

                // region id
                DigitizingDataDomain.Model.VslaRegion vslaRegion = new DigitizingDataDomain.Model.VslaRegion();
                vslaRegion.RegionId = Convert.ToInt32(request.RegionName);
                vsla.VslaRegion     = vslaRegion;

                VslaRepo vslaRepo = new VslaRepo();
                Boolean  result   = vslaRepo.Insert(vsla);
                if (result)
                { // SUCCESS
                    operationResult.operation = "create";
                    operationResult.result    = "1";
                    operationResult.VslaCode  = _vslaCode;
                }
                else
                { // FAILED
                    operationResult.operation = null;
                    operationResult.result    = "-1";
                    operationResult.VslaCode  = null;
                }
            }
            catch (Exception e)
            {
            }
            return(operationResult);
        }
        // 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);
        }