A second operation started on this context before a previous asynchronous

Viewed 35

hai im new on c# actually i have an issue with my code which i couldnt find the error. I making a controller which i can see the details that user sumbit. When im debug it say that " Use 'await' to ensure that any asynchronous operations". i try to put await every each of line but doesnt working.

plus in my cases i dont use for each method

here is my code :-

public async Task<ActionResult> Details(int id, string currentFilter)
    {
        try
        {

            BizRepMaster bizRepmaster = _bizRepMasterService.Find(id);
            
            

            if (bizRepmaster.RepCountry != null)
                ViewBag.BizCountry = _countryMasterService.Find(bizRepmaster.RepCountry).tCountry;
            else
                ViewBag.BizCountry = "";

            
            if (bizRepmaster.RepState == null)
            {
                ViewBag.State = "";
            }
            else
            {
                if (bizRepmaster.RepState == "Oth")
                {
                    ViewBag.State = "Others";
                }

                else
                {
                    ViewBag.State = GetStateName(bizRepmaster.RepCountry, bizRepmaster.RepState);
                    
                }
            }
            if (bizRepmaster.MailState == null)
            {
                ViewBag.MailState = "";
            }
            else
            {
                if (bizRepmaster.RepState == "Oth")
                {
                    ViewBag.MailState = "Others";
                }

                else
                {
                    ViewBag.MailState = GetBizStateName(bizRepmaster.RepCountry, bizRepmaster.MailState);
                }
            }
            ViewBag.AMNationality = _countryMasterService.GetCountryMaster()
                        .Where(a => a.tISO == bizRepmaster.RepNationality).Single().tCountry;
            ViewBag.AMIdType = _idTypeService.GetIdTypes()
                        .Where(a => a.TypeID == bizRepmaster.RepIdType).Single().LabelName;

            
            if (bizRepmaster.DialCode != null)
            {
                ViewBag.DialCode = _unitOfWorkAsync.Repository<Country>().Find(bizRepmaster.DialCode).tDialCode;
            }
            if (bizRepmaster.NatureOfBusiness != null)
            {
                
            }
            ViewBag.AMResType = _unitOfWorkAsync.Repository<ResidencyType>().Find(bizRepmaster.RepResidencyType).LabelName;
            ViewBag.AMJobType = _unitOfWorkAsync.Repository<SenderJobType>().Find(bizRepmaster.RepJobType).LabelName;

            ViewBag.StateList = new SelectList(_stateService.GetStates(), "nId", "tStateDesc");
            if (bizRepmaster.IdType != null)
                ViewBag.IdTypeList = _idTypeService.Find(Convert.ToInt32(bizRepmaster.RepIdType)).LabelName; 

            ViewBag.CreatedUserName = _userProfileService.GetUserProfile().Where(a => a.UserID == Convert.ToInt32(bizRepmaster.CreatedBy)).Single().LoginId;
            if (bizRepmaster.ApprovedBy != null)
            {
                ViewBag.ApprovedUserName = _userProfileService.GetUserProfile().Where(a => a.UserID == Convert.ToInt32(bizRepmaster.ApprovedBy)).Single().LoginId;
            }

            if (bizRepmaster.LastUpdatedBy != null)
            {
                ViewBag.LastUpdatedName = _userProfileService.GetUserProfile().Where(a => a.UserID == Convert.ToInt32(bizRepmaster.LastUpdatedBy)).Single().LoginId;
            }
            if (bizRepmaster.LastApprovedBy != null)
            {

                ViewBag.LastApprovedName = _userProfileService.GetUserProfile().Where(a => a.UserID == Convert.ToInt32(bizRepmaster.LastApprovedBy)).Single().LoginId;
            }
            ViewBag.SenderId1 = bizRepmaster.SenderId;
            return View("_BizRepDetails", bizRepmaster);
        }
        catch (Exception ex)
        {
            return PartialView("_ErrorMessageView");
        }
    }
0 Answers
Related