Exemple #1
0
        public object SaveMapOrRemapCbsAccount(BatchUpdateModel model)
        {
            StringBuilderService builder = new StringBuilderService();
            var cbsInfosList             = ConvertBatchUpdateModelToMtCbsinfoModel(model);

            string inactiveCbsAccountNo = string.Empty;
            int    allowAccNo           = 3;
            int    count        = 0;
            int    countPending = 0;
            int    totalCount   = 0;
            bool   allowMap     = false;

            count = _repository.CheckEligibilityMappingByMphone(cbsInfosList[0].Mphone);
            foreach (var value in cbsInfosList)
            {
                if (value.MakeStatus == "A")
                {
                    countPending++;
                }
            }
            totalCount = count + countPending;
            if (count <= 2 && totalCount <= 3)
            {
                allowMap = true;
            }
            if (totalCount > 3)
            {
                return("Please do not try to activate more than three account");
            }
            if (countPending > 3)
            {
                return("Please do not try to activate more than three account");
            }
            if (count > 3)
            {
                return("Three accont activated already");
            }
            foreach (var item in cbsInfosList)
            {
                bool isRegInfoExist = _repository.IsRegInfoExist(item.Mphone);

                if (!isRegInfoExist)
                {
                    return("Ok Account: " + item.Mphone + " is Not exist");                    //reginfo not exist
                }
                if (String.IsNullOrEmpty(item.MakeBy))
                {
                    return(HttpStatusCode.Unauthorized);
                }
                if (item.Status == null && item.MakeStatus == "A")
                {
                    var IsAccNoIsMappedByMblNo = _repository.CheckAccNoIsMappedByMblNo(item.Mobnum, item.Accno);
                    if (Convert.ToInt32(IsAccNoIsMappedByMblNo) == 0)
                    {
                        _repository.Add(item);
                        auditTrailService.InsertModelToAuditTrail(item, item.MakeBy, 8, 3, "Customer Acc Mapping", item.Mphone, "Mapped Suucessful");
                    }
                    else
                    {
                        return(HttpStatusCode.BadRequest);
                    }
                }
                if ((item.Status != item.MakeStatus) && item.Status != null)
                {
                    if (item.MakeStatus == "A")
                    {
                        if (allowMap)
                        {
                            var cbsInfoPrev = _repository.GetMappedAccountByAccNo(item.Accno);
                            _repository.ActiveCbsAccountByAccountNo(item.Accno, item.MakeBy, item.Ubranch);
                            var cbsInfoCurrent = _repository.GetMappedAccountByAccNo(item.Accno);
                            auditTrailService.InsertUpdatedModelToAuditTrail(cbsInfoCurrent, cbsInfoPrev, item.MakeBy, 8, 4, "Customer Acc Mapping", item.Mphone, "Successfully Map or Remapped");
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        var cbsInfoPrev = _repository.GetMappedAccountByAccNo(item.Accno);
                        _repository.InactiveCbsAccountByAccountNo(item.Accno, item.MakeBy, item.Ubranch);
                        var cbsInfoCurrent = _repository.GetMappedAccountByAccNo(item.Accno);
                        auditTrailService.InsertUpdatedModelToAuditTrail(cbsInfoCurrent, cbsInfoPrev, item.MakeBy, 8, 4, "Customer Acc Mapping", item.Mphone, "Successfully Map or Remapped");
                    }
                }
            }
            return(HttpStatusCode.OK);
        }