/// <summary> Subscribes to Event-Bus </summary> /// <param name="event"> data received from event bus</param> /// <returns></returns> public async Task Handle(FormularyUpdatedIntegrationEvent @event) { try { if (@event != null) { _logger.LogInformation(string.Format(CommonConstants.LoggingMessage.DataReceivedFromFormulary, JsonConvert.SerializeObject(@event))); var formularyRequestModel = new BusinessLayer.Models.Formulary { FormularyId = @event.FormularyId, ItemId = @event.ItemId, Description = @event.Description, IsActive = @event.IsActive, }; await _formularyManager.ProcessFormularyRequest(formularyRequestModel); } else { _logger.LogError(CommonConstants.LoggingMessage.InvalidRequest); } await Task.CompletedTask; } catch (Exception ex) { _logger.LogError(string.Format(CommonConstants.LoggingMessage.ErrorWhileProcessingRequest, ex.Message)); } }
/// <summary> Subscribes to Event-Bus </summary> /// <param name="event"> data received from event bus</param> /// <returns></returns> public async Task Handle(FormularyFacilityUpdatedIntegrationEvent @event) { try { if (@event != null && @event.FormularyId > 0 && @event.FacilityId > 0) { _logger.LogInformation(string.Format(CommonConstants.LoggingMessage.DataReceivedFromFormularyFacility, JsonConvert.SerializeObject(@event))); var formularyRequestModel = new BusinessLayer.Models.Formulary { FormularyId = @event.FormularyId, FacilityFormulary = new BusinessLayer.Models.FacilityFormulary { FacilityId = @event.FacilityId, AduIgnoreCritLow = @event.AduIgnoreCritLow, AduIgnoreStockout = @event.AduIgnoreStockout, Approved = @event.Approved } }; await _formularyManager.UpdateFormularyFacility(formularyRequestModel); } else { _logger.LogError(CommonConstants.LoggingMessage.InvalidRequest); } await Task.CompletedTask; } catch (Exception ex) { _logger.LogError(string.Format(CommonConstants.LoggingMessage.ErrorWhileProcessingRequest, ex.Message)); } }
/// <summary> /// This method is used to store a formulary facility in DB. /// </summary> /// <param name="formulary">formulary facility to be updated.</param> public async Task <bool> UpdateFormularyFacility(BusinessLayer.Models.Formulary formulary) { if (formulary != null && formulary.FacilityFormulary != null) { var entity = await GetFormularyById(formulary.FormularyId); if (entity != null) { if (entity.FacilityFormulary == null) { entity.FacilityFormulary = new FacilityFormulary(); } entity.FacilityFormulary.FacilityId = formulary.FacilityFormulary.FacilityId; entity.FacilityFormulary.AduIgnoreStockout = formulary.FacilityFormulary.AduIgnoreStockout; entity.FacilityFormulary.AduIgnoreCritLow = formulary.FacilityFormulary.AduIgnoreCritLow; entity.FacilityFormulary.Approved = formulary.FacilityFormulary.Approved; entity.ModifiedBy = UserName.Admin.ToString(); entity.ModifiedDate = DateTime.Now; await _collection.ReplaceOneAsync(e => e.FormularyId == entity.FormularyId, entity); return(true); } } return(false); }
/// <summary> /// Inserts a formulary in DB. /// </summary> /// <param name="formulary">Formulary to be stored in db.</param> public async Task <bool> InsertFormulary(BusinessLayer.Models.Formulary formulary) { if (formulary != null) { var entity = _mapper.Map <Formulary>(formulary); entity.CreatedBy = UserName.Admin.ToString(); entity.CreatedDate = DateTime.Now; entity.ModifiedBy = UserName.Admin.ToString(); entity.ModifiedDate = DateTime.Now; await _collection.InsertOneAsync(entity); return(true); } ; return(false); }
/// <summary> /// Update a formulary in DB. /// </summary> /// <param name="formulary">Formulary to be updated in db.</param> public async Task <bool> UpdateFormulary(BusinessLayer.Models.Formulary formulary) { var entity = await GetFormularyById(formulary.FormularyId); if (entity != null) { entity.IsActive = formulary.IsActive ?? false; entity.Description = formulary.Description; entity.ItemId = formulary.ItemId; entity.ModifiedBy = UserName.Admin.ToString(); entity.ModifiedDate = DateTime.Now; await _collection.ReplaceOneAsync(e => e.FormularyId == entity.FormularyId, entity); return(true); } return(false); }