Ejemplo n.º 1
0
        private GenericResult HandleCommand(
            OrderStateMachine.Trigger trigger,
            ITriggerContext context,
            IOrderEditableData editableData = null,
            IOrderDealingData dealingData   = null,
            IOrderCoreData coreData         = null,
            TriggerStatus status            = TriggerStatus.Done)
        {
            Contract.Requires(context != null, "context != null");

            _workingData = CurrentData.Clone()
                           .SetRoutingData(dealingData)
                           .SetEditableData(editableData)
                           .SetTrigger(trigger)
                           .SetPendingTrigger(status.IsPendingReply() && this.PendingTrigger == trigger ? null : this.PendingTrigger);
            var result = EnforceTriggerStatus(trigger, ref status);

            if (result.IsFailure())
            {
                return(result);
            }
            if (status == TriggerStatus.Rejected)
            {
                result = GenericResult.Success();
            }
            else
            {
                var triggerSucceeded = status == TriggerStatus.Pending ? _stateMachine.CanFireTrigger(trigger) : _stateMachine.TryFireTrigger(trigger);
                result = triggerSucceeded ? GenericResult.Success() : GenericResult.Failure(string.Concat(_workingData.StateMachineErrorMessage, String.Format("The commmand {0} is not allowed when the order is in {1} state", trigger, OrderState)));
            }
            if (result.IsSuccess())
            {
                _workingData.SetOrderState(_stateMachine.GetState);
                if (editableData != null)
                {
                    if (coreData != null)
                    {
                        this.InsertDataFrom(coreData);
                    }
                    EventLogs.Add(new OrderParameterEventLog <IOrderEditableData>(context, trigger, status, _workingData.OrderState, this, editableData));
                }
                else if (dealingData != null)
                {
                    EventLogs.Add(new OrderParameterEventLog <IOrderDealingData>(context, trigger, status, _workingData.OrderState, this, dealingData));
                    if (dealingData.Trade != null)
                    {
                        _workingData.SetExecutionQuantity(ComputeExecutionQuantity(_workingData.Side));
                    }
                }
                else
                {
                    EventLogs.Add(new OrderEventLog(context, trigger, status, _workingData.OrderState, this));
                }
                _workingData.SetOrderStatus(ComputeOrderStatus(_workingData));
                RefreshCurrentData(_workingData);
            }
            _workingData = null;
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Save([FromBody] RespuestaFormModel formModel)
        {
            GenericResult itemResult = null;

            try
            {
                if (await _authorizationService.AuthorizeAsync(User))
                {
                    if (ModelState.IsValid)
                    {
                        var respuesta = _respuestaService.Get(formModel.Id) ?? new Respuesta();

                        respuesta.Valor          = formModel.Valor;
                        respuesta.Detalle        = formModel.Detalle;
                        respuesta.FechaRespuesta = formModel.FechaRespuesta;

                        if (respuesta.Id == Guid.Empty)
                        {
                            respuesta.CreadoPor = User.Identity.Name;
                            respuesta.CreadoEn  = DateTime.Now;
                        }

                        respuesta.ActualizadoPor = User.Identity.Name;
                        respuesta.ActualizadoEn  = DateTime.Now;

                        var estandar = _estandarService.Get(formModel.EstandarId);
                        respuesta.Estandar = estandar;

                        var evaluacion = _evaluacionService.Get(formModel.EvaluacionId);
                        respuesta.Evaluacion = evaluacion;

                        var confirmation = _respuestaService.SaveOrUpdate(respuesta);
                        if (confirmation.WasSuccessful)
                        {
                            itemResult = GenericResult.Ok(confirmation.Message);
                            var item = confirmation.Value as Respuesta;
                            itemResult.ReturnValue = new { Id = item.Id };
                        }
                        else
                        {
                            itemResult = GenericResult.Failure(confirmation.Message);
                        }
                    }
                }
                else
                {
                    var codeResult = new CodeResultStatus(401);
                    return(Ok(codeResult));
                }
            }
            catch (Exception exception)
            {
                itemResult = GenericResult.Failure(exception.Message);
            }

            return(Ok(itemResult));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Create([FromBody] EvaluacionFormModel formModel)
        {
            GenericResult itemResult = null;

            try
            {
                if (await _authorizationService.AuthorizeAsync(User))
                {
                    if (ModelState.IsValid)
                    {
                        var evaluacion = new Evaluacion
                        {
                            NombreMIC       = formModel.NombreMIC,
                            NombreRGM       = formModel.NombreRGM,
                            PosicionMIC     = _evaluacionService.GetPosicion(formModel.Posicion),
                            TipoVisita      = formModel.TipoVisita,
                            ParteDelDia     = formModel.ParteDia,
                            TipoEvaluacion  = _evaluacionService.GetTipoEvaluacion(formModel.TipoEvaluacion),
                            Local           = _localService.Get(formModel.IdLocal),
                            Estado          = _statusService.Online(),
                            FechaEvaluacion = DateTime.Now,
                            HoraEvaluacion  = DateTime.Now,
                            ActualizadoEn   = DateTime.Now,
                            CreadoEn        = DateTime.Now,
                            ActualizadoPor  = "admin",
                            CreadoPor       = "admin",
                        };

                        var confirmation = _evaluacionService.SaveOrUpdate(evaluacion);
                        if (confirmation.WasSuccessful)
                        {
                            var respConfirmation = _evaluacionService.CreateRespuestasByEvaluacion(evaluacion.Id);

                            itemResult = GenericResult.Ok(confirmation.Message);
                            var item = confirmation.Value as Evaluacion;
                            itemResult.ReturnValue = new { Id = item.Id };
                        }
                        else
                        {
                            itemResult = GenericResult.Failure(confirmation.Message);
                        }
                    }
                }
                else
                {
                    var codeResult = new CodeResultStatus(401);
                    return(Ok(codeResult));
                }
            }
            catch (System.Exception exception)
            {
                itemResult = GenericResult.Failure(exception.Message);
            }

            return(Ok(itemResult));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> SaveByLocal([FromBody] ImagenLocalFormModel formModel)
        {
            GenericResult itemResult = null;

            try
            {
                if (await _authorizationService.AuthorizeAsync(User))
                {
                    var imagenLocal = _localService.GetImage(formModel.Id) ?? new ImagenLocal();

                    if (imagenLocal.Id == Guid.Empty)
                    {
                        imagenLocal.CreadoEn  = DateTime.Now;
                        imagenLocal.CreadoPor = User.Identity.Name;
                    }

                    imagenLocal.ActualizadoEn  = DateTime.Now;
                    imagenLocal.ActualizadoPor = User.Identity.Name;
                    imagenLocal.Descripcion    = !string.IsNullOrEmpty(formModel.Descripcion) ? formModel.Descripcion : "";
                    imagenLocal.Tipo           = formModel.Tipo;
                    imagenLocal.Orden          = formModel.Orden;

                    var local = _localService.Get(formModel.LocalId);
                    imagenLocal.Local = local;

                    if (!string.IsNullOrEmpty(formModel.ImagenData))
                    {
                        var imageBase64 = formModel.ImagenData.Replace("data:image/jpeg;base64,", "");
                        var imageBytes  = Convert.FromBase64String(imageBase64);
                        var imageUrl    = _blobImageService.UploadImage(imageBytes, BlobContainers.Locales());
                        imagenLocal.Imagen = imageUrl;
                    }

                    ActionConfirmation confirmation = _localService.SaveOrUpdateImagen(imagenLocal);
                    if (confirmation.WasSuccessful)
                    {
                        itemResult = GenericResult.Ok(confirmation.Message);
                        var item = confirmation.Value as ImagenLocal;
                        itemResult.ReturnValue = new { Id = item.Id };
                    }
                    else
                    {
                        itemResult = GenericResult.Failure(confirmation.Message);
                    }
                }
            }
            catch (Exception exception)
            {
                itemResult = GenericResult.Failure(exception.Message);
            }

            return(Ok(itemResult));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Used to set a character's attributes up.
        /// </summary>
        /// <param name="callerId">The user identifier of the caller.</param>
        /// <param name="values">What to set the initial attributes to.</param>
        public async Task <IResult> SetStatisticAsync(ulong callerId, string statName, int?newValue = null, bool force = false)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var statistic = await _statProvider.GetStatisticAsync(statName);

            if (statistic == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            try
            {
                if (force)
                {
                    var statValue = character.GetStatistic(statistic);

                    if (newValue.HasValue)
                    {
                        statValue.Value = newValue.Value;
                    }
                }
                else
                {
                    await _strategy.SetStatistic(character, statistic, newValue);
                }

                await _charProvider.UpdateCharacterAsync(character);

                return(StatisticResult.StatisticSetSucessfully());
            }
            catch (System.Exception e)
            {
                if (!(e is ProgressionException))
                {
                    System.Console.WriteLine(e);
                }

                return(GenericResult.Failure(e.Message));

                throw e;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Used to set a character's proficiencies up.
        /// </summary>
        /// <param name="callerId">The user identifier of the caller.</param>
        /// <param name="values">What to set the initial attributes to.</param>
        public async Task <IResult> SetProficiencyAsync(ulong callerId, string statName, bool isProficient, bool force = false)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var statistic = await _statProvider.GetStatisticAsync(statName);

            if (statistic == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            try
            {
                if (force)
                {
                    var statVal = character.GetStatistic(statistic);
                    statVal.IsProficient = isProficient;
                }
                else
                {
                    await _strategy.SetProficiency(character, statistic, isProficient);
                }

                await _charProvider.UpdateCharacterAsync(character);

                return(StatisticResult.StatisticSetSucessfully());
            }
            catch (System.Exception e)
            {
                return(GenericResult.Failure(e.Message));

                throw e;
            }
        }
Ejemplo n.º 7
0
        public async Task SetStatisticAsync_NotEnoughPoints_ReturnNotEnoughPoints()
        {
            // Arrange
            int points    = 1;
            int luckScore = 2;

            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var statOptions  = new StatisticOptions
            {
                InitialAttributeMax    = 10,
                InitialAttributePoints = points
            };

            var controller = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, statOptions));

            // Act
            var result = await controller.SetStatisticAsync(1, "luck", 2);

            // Assert
            // TODO: update unit tests to match new result
            Assert.Equal(GenericResult.Failure(
                             string.Format(Messages.STAT_NOT_ENOUGH_POINTS, luckScore, points)), result);
        }