public override async Task <ExecutionStatusResponse> CreatePromo(PromoCreateRequest request, ServerCallContext context) { var toSaveCode = new PromoCode() { Code = PromoGenerator.GenerateCode(), Title = request.Title, ExpirationDate = Convert.ToDateTime(request.ExpirationDate), Discount = request.Discount }; var res = new ExecutionStatusResponse { Status = false }; try { await _repository.CreateAsync(toSaveCode); res.Status = true; return(res); } catch (Exception e) { _logger.LogError($"[PROMO-CREATION]<>Some errors occured: {e.Message}"); } return(res); }
protected static Message WrapInMessage(ProtoExecutionResult executionResult, Message request) { var executionStatusResponse = ExecutionStatusResponse.CreateBuilder() .SetExecutionResult(executionResult) .Build(); return(Message.CreateBuilder() .SetMessageId(request.MessageId) .SetMessageType(Message.Types.MessageType.ExecutionStatusResponse) .SetExecutionStatusResponse(executionStatusResponse) .Build()); }
private static Message GetResponseMessage(Message request) { var executionStatusResponseBuilder = ExecutionStatusResponse.CreateBuilder(); var executionStatusResponse = executionStatusResponseBuilder.SetExecutionResult( ProtoExecutionResult.CreateBuilder().SetFailed(false).SetExecutionTime(0)).Build(); return(Message.CreateBuilder() .SetMessageId(request.MessageId) .SetMessageType(Message.Types.MessageType.ExecutionStatusResponse) .SetExecutionStatusResponse(executionStatusResponse) .Build()); }
protected static Message WrapInMessage(ProtoExecutionResult executionResult, Message request) { var executionStatusResponse = new ExecutionStatusResponse { ExecutionResult = executionResult }; return(new Message { MessageId = request.MessageId, MessageType = Message.Types.MessageType.ExecutionStatusResponse, ExecutionStatusResponse = executionStatusResponse }); }
public override async Task <ExecutionStatusResponse> DeleteInvalidPromos(DeleteInvalidPromosRequest request, ServerCallContext context) { var multiDeletionRes = new ExecutionStatusResponse() { Status = false }; try { await _repository.DeleteInvalidPromoAsync(); } catch (Exception e) { _logger.LogError($"[PROMO-MULTI_INVALID_DELETION]<>Some errors occured: {e.Message}"); } return(multiDeletionRes); }
private static Message GetResponseMessage(Message request) { var response = new ExecutionStatusResponse { ExecutionResult = new ProtoExecutionResult { Failed = false, ExecutionTime = 0 } }; return(new Message { MessageId = request.MessageId, MessageType = Message.Types.MessageType.ExecutionStatusResponse, ExecutionStatusResponse = response }); }
public override async Task <ExecutionStatusResponse> GeneratePromoCodes(GeneratePromoRequest request, ServerCallContext context) { List <PromoCode> promoCodesToSave = new List <PromoCode>(); var genResult = new ExecutionStatusResponse() { Status = false }; try { for (int i = 0; i < request.Quantity; i++) { PromoCode pc = new PromoCode() { Code = PromoGenerator.GenerateCode(), Title = request.Title, ExpirationDate = request.ExpirationDate.ToDateTime(), Discount = request.Discount }; promoCodesToSave.Add(pc); } await _repository.CreateManyAsync(promoCodesToSave); genResult.Status = true; return(genResult); } catch (Exception e) { _logger.LogError($"[PROMO-GENERATION]<>Some errors occured: {e.Message}"); } return(genResult); }