public async Task <int> Insert_DrugBrandForDiagnosis(DrugBrandsForDiagnosisVM vm, int userId) { int brandId = 0; //## If no ID provided- then Create a New Brand and Insert the Brand<->Diagnosis links if (vm.Id < 1) { DrugBrands drugBrands = new DrugBrands() { DrugId = vm.DrugId, BrandName = vm.Name, ManufacturerId = vm.ManufacturerId, DateAdded = DateTime.Now, BrandForIndications = new List <BrandForIndications>() { new BrandForIndications() { IndicationTypeId = vm.IndicationsTypeId, AddedBy = userId } } }; await _context.DrugBrands.AddAsync(drugBrands); await _context.SaveChangesAsync(); brandId = drugBrands.Id; } else { //## DrugBrand Exist-- Just create a new Brand to Doagnosis Assignment BrandForIndications brandForIndications = new BrandForIndications() { DrugBrandId = vm.Id, IndicationTypeId = vm.IndicationsTypeId, AddedBy = userId }; await _context.BrandForIndications.AddAsync(brandForIndications); await _context.SaveChangesAsync(); brandId = vm.Id; } //## Now Update the Cache- insert the new Value in the Redis cache var cachedList = await ListAllBrandsForDiagnosis(vm.IndicationsTypeId); cachedList.Add(vm); string cacheKey = $"ListAllBrandsForDiagnosis_{vm.IndicationsTypeId}"; _cacheService.SetCacheValue(cacheKey, cachedList); return(brandId); //## Return BrandID- so we can Add this new brand in the SelectList - with Value/Id }
public async Task <ActionResult> Insert_DrugBrandForDiagnosis(DrugBrandsForDiagnosisVM vm) { if (vm is null) { return(Json("error")); } AppUserDetailsVM currentUser = await GetCurrentUser(); var result = await _drugService.Insert_DrugBrandForDiagnosis(vm, currentUser.Id); return(Json(result)); }