Ejemplo n.º 1
0
        public async Task <IActionResult> PutTransactionPriority(string tranPriorityKey, TransactionPriorityPut transactionPriorityPut)
        {
            Models.TransactionPriority objTransactionPriority = new Models.TransactionPriority();
            try
            {
                var facilityKey = RouteData.Values["facilitykey"].ToString();
                var headers     = Request.Headers.ToDictionary <KeyValuePair <string, StringValues>, string, string>(item => item.Key, item => item.Value);
                BusinessResponse objBusinessResponse = await _manager.UpdateTransactionPriorityAsync(tranPriorityKey, transactionPriorityPut, Utility.ParseStringToGuid(facilityKey), headers);

                if (objBusinessResponse.IsSuccesss)
                {
                    _logger.LogInformation(objBusinessResponse.Message);
                    return(Ok(objBusinessResponse.Message));
                }
                else
                {
                    _logger.LogInformation(objBusinessResponse.Message);
                    return(BadRequest(new ErrorResponse(objBusinessResponse.Message, (int)HttpStatusCode.BadRequest, ResponsePayloadType.BusinessException)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }
Ejemplo n.º 2
0
        public async Task <BusinessResponse> AddTransactionPriority(TransactionPriorityPost transactionPriorityPost, Guid facilityID, Dictionary <string, string> headers)
        {
            Models.TransactionPriority objTransactionPriority = new Models.TransactionPriority();

            bool?codeExist = _transactionPriorityRepository.GetAll().ToList()?.Any(x => x.PriorityCode.Trim().ToLower() == transactionPriorityPost.PriorityCode.Trim().ToLower());

            if (codeExist != null && codeExist == true)
            {
                return(new BusinessResponse()
                {
                    IsSuccesss = false, Message = transactionPriorityPost.PriorityCode + " code already exist."
                });
            }

            var newID = Utility.GetNewGuid();

            objTransactionPriority.Id                      = newID;
            objTransactionPriority.TenantKey               = Guid.Parse(_executionContextAccessor.Current.Tenant.TenantKey);
            objTransactionPriority.FacilityKey             = facilityID;
            objTransactionPriority.PrintLabelKey           = Guid.Parse("5c43149d-7c13-49f5-a19d-c0c4f4e58431");
            objTransactionPriority.PriorityCode            = transactionPriorityPost.PriorityCode;
            objTransactionPriority.PriorityName            = transactionPriorityPost.PriorityName;
            objTransactionPriority.PriorityOrder           = 1;
            objTransactionPriority.LegendBackColor         = transactionPriorityPost.LegendForeColor;
            objTransactionPriority.LegendForeColor         = transactionPriorityPost.LegendBackColor;
            objTransactionPriority.MaxOnHoldLength         = 0;
            objTransactionPriority.ForManualPickFlag       = transactionPriorityPost.ForManualPickFlag;
            objTransactionPriority.ForManualRestockFlag    = transactionPriorityPost.ForManualRestockFlag;
            objTransactionPriority.ADUFlag                 = transactionPriorityPost.ADUFlag;
            objTransactionPriority.AutoReceiveFlag         = false;
            objTransactionPriority.ActiveFlag              = transactionPriorityPost.ActiveFlag;
            objTransactionPriority.SystemFlag              = true;
            objTransactionPriority.UseInterfaceMedNameFlag = transactionPriorityPost.UseInterfaceMedNameFlag;
            objTransactionPriority.CreatedByActorKey       = Utility.GetNewGuid();
            objTransactionPriority.LastModifiedByActorKey  = Utility.GetNewGuid();
            objTransactionPriority.CreatedDateTime         = DateTimeOffset.Now;
            objTransactionPriority.LastModifiedUTCDateTime = DateTime.UtcNow;

            var maxOrder = 1;

            if (_transactionPriorityRepository.GetAll()?.ToList()?.Count > 0)
            {
                maxOrder = _transactionPriorityRepository.GetAll().Select(i => i.PriorityOrder).Max() + 1;
            }
            objTransactionPriority.PriorityOrder = maxOrder;

            await _transactionPriorityRepository.AddAsync(objTransactionPriority);

            _unitOfWork.CommitChanges();
            SendEvent(GetTransactionPriorityById(newID.ToString()), "Add", headers);
            return(new BusinessResponse()
            {
                IsSuccesss = true, Message = objTransactionPriority.Id.ToString()
            });
        }
        /// <summary>
        /// This method is used to store a Priority in DB.
        /// </summary>
        /// <param name="priority">Priority to be inserted/updated.</param>
        public async Task <bool> ProcessTransactionPriorityRequest(Models.TransactionPriority priority)
        {
            _logger.LogInformation(string.Format(CommonConstants.LoggingMessage.TransactionPriorityDataReceivedFromFacility, JsonConvert.SerializeObject(priority)));
            var result = await _transactionPriorityRepository
                         .GetPriorityByFacilityIdAndPriorityCode(priority.FacilityId, priority.TransactionPriorityCode);

            if (result == null)
            {
                return(await _transactionPriorityRepository.InsertTransactionPriority(priority));
            }
            else
            {
                return(await _transactionPriorityRepository.UpdateTransactionPriority(priority));
            }
        }
Ejemplo n.º 4
0
        private void SendEvent(Models.TransactionPriority transactionPriorityById, string type, Dictionary <string, string> headers)
        {
            var eventMessage = new TransactionPriorityEvent
            {
                Message   = transactionPriorityById,
                EventType = type
            };

            try{
                _eventBus.Publish(_configuration.TransactionPriority, eventMessage, headers);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public async Task <BusinessResponse> UpdateTransactionPriorityAsync(string tranPriorityKey, TransactionPriorityPut transactionPriorityPut, Guid facilityKey, Dictionary <string, string> headers)
        {
            Models.TransactionPriority objTransactionPriority = new Models.TransactionPriority();
            objTransactionPriority = _transactionPriorityRepository.GetByTransactionPriorityAndFacilityKey(Guid.Parse(tranPriorityKey), facilityKey);

            if (objTransactionPriority != null)
            {
                objTransactionPriority.PriorityName         = transactionPriorityPut.PriorityName;
                objTransactionPriority.LegendBackColor      = transactionPriorityPut.LegendBackColor;
                objTransactionPriority.LegendForeColor      = transactionPriorityPut.LegendForeColor;
                objTransactionPriority.MaxOnHoldLength      = transactionPriorityPut.MaxOnHoldLength;
                objTransactionPriority.ForManualPickFlag    = transactionPriorityPut.ForManualPickFlag;
                objTransactionPriority.ForManualRestockFlag = transactionPriorityPut.ForManualRestockFlag;
                objTransactionPriority.ADUFlag    = transactionPriorityPut.ADUFlag;
                objTransactionPriority.ActiveFlag = transactionPriorityPut.ActiveFlag;
                objTransactionPriority.SystemFlag = transactionPriorityPut.SystemFlag;
                objTransactionPriority.UseInterfaceMedNameFlag = transactionPriorityPut.UseInterfaceMedNameFlag;
                objTransactionPriority.LastModifiedByActorKey  = Guid.NewGuid();
                objTransactionPriority.LastModifiedUTCDateTime = DateTime.UtcNow;
                if (transactionPriorityPut.PriorityOrder != objTransactionPriority.PriorityOrder)
                {
                    if (objTransactionPriority.PriorityOrder > transactionPriorityPut.PriorityOrder)
                    {
                        await _transactionPriorityRepository.UpdatePriorityOrderUpAsync(transactionPriorityPut.PriorityOrder);
                    }
                    else
                    {
                        await _transactionPriorityRepository.UpdatePriorityOrderDownAsync(transactionPriorityPut.PriorityOrder, objTransactionPriority.PriorityOrder);
                    }
                }
                objTransactionPriority.PriorityOrder = transactionPriorityPut.PriorityOrder;
                _transactionPriorityRepository.Update(objTransactionPriority);
                _unitOfWork.CommitChanges();
                SendEvent(GetTransactionPriorityById(tranPriorityKey), "Update", headers);
                return(new BusinessResponse()
                {
                    IsSuccesss = true, Message = "TransactionPriority Update."
                });
            }
            else
            {
                return(new BusinessResponse()
                {
                    IsSuccesss = false, Message = "No TransactionPriority Exist to update."
                });
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <TransactionPriorityPost> > PostTransactionPriority([FromBody] TransactionPriorityPost transactionPriorityPost)
        {
            Models.TransactionPriority objTransactionPriority = new Models.TransactionPriority();
            try
            {
                var validationResult = _entityValidator.Validate(transactionPriorityPost);
                if (!validationResult.IsValid)
                {
                    StringBuilder validationMessages = new StringBuilder();
                    foreach (var error in validationResult.Errors)
                    {
                        validationMessages.Append(error + " ");
                    }
                    ErrorMessage objErrorMessage = new ErrorMessage()
                    {
                        ErrorCode = 400, ErrorDescription = validationMessages.ToString()
                    };
                    _logger.LogInformation(validationMessages.ToString());
                    return(BadRequest(new ErrorResponse(validationMessages.ToString(), (int)HttpStatusCode.BadRequest, ResponsePayloadType.BusinessException)));
                }
                var headers     = Request.Headers.ToDictionary <KeyValuePair <string, StringValues>, string, string>(item => item.Key, item => item.Value);
                var facilityKey = RouteData.Values["facilitykey"].ToString();
                BusinessResponse objBusinessResponse = await _manager.AddTransactionPriority(transactionPriorityPost, Utility.ParseStringToGuid(facilityKey), headers);

                if (objBusinessResponse.IsSuccesss)
                {
                    return(CreatedAtAction(nameof(GetTransactionPriority), new { tranPriorityKey = objBusinessResponse.Message }, transactionPriorityPost));
                }
                else
                {
                    _logger.LogInformation(objBusinessResponse.Message);
                    return(BadRequest(new ErrorResponse(objBusinessResponse.Message, (int)HttpStatusCode.BadRequest, ResponsePayloadType.BusinessException)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }