コード例 #1
0
        public IHttpActionResult ChangeUserData(UpdateUserDataRequest model)
        {
            GeneralResponse             oResponse     = new GeneralResponse();
            FieldsService               oFieldService = new FieldsService();
            Dictionary <string, string> oErrors       = oFieldService.ValidateModel(ModelState);

            try
            {
                if (oErrors.Count != 0)
                {
                    throw new ArgumentException("Error, campos invalidos");
                }


                var    claims = ClaimsPrincipal.Current.Identities.First().Claims.ToList();
                string UserId = claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Sid, StringComparison.OrdinalIgnoreCase))?.Value;

                UserManager oUserManager = new UserManager();
                oUserManager.UpdateDataByUserId(UserId, model.PhoneNumber, model.Email);

                User oUser = oUserManager.GetByUserId(UserId);

                var oUserResponse = new
                {
                    Cuil        = oUser.Cuil,
                    Name        = oUser.Name,
                    Surname     = oUser.Surname,
                    Email       = oUser.Email,
                    PhoneNumber = oUser.PhoneNumber,
                };

                oResponse.Success = 1;
                oResponse.Message = "Exito - se han registrado los nuevos datos del usuario";
                oResponse.Data    = oUserResponse;

                return(Content(HttpStatusCode.OK, oResponse));
            } catch (ArgumentException ex)
            {
                oResponse.Success = 0;
                oResponse.Message = ex.Message;
                oResponse.Data    = oErrors;

                return(Content(HttpStatusCode.BadRequest, oResponse));
            }
            catch (Exception ex)
            {
                oResponse.Success = 0;
                oResponse.Message = "Error - no se ha podido registrar los nuevos datos del usuario";
                oResponse.Data    = ex.Message;

                return(Content(HttpStatusCode.BadRequest, oResponse));
            }
        }
コード例 #2
0
        public IHttpActionResult Post(CreditCardDepositRequest model)
        {
            GeneralResponse oResponse       = new GeneralResponse();
            DepositManager  oDepositManager = new DepositManager();
            AccountManager  oAccountManager = new AccountManager();
            FieldsService   oFieldsService  = new FieldsService();

            try
            {
                Dictionary <string, string> oErrors = oFieldsService.ValidateModel(ModelState);
                if (oErrors.Count != 0)
                {
                    oResponse.Success = 0;
                    oResponse.Message = "Error, campos invalidos";
                    oResponse.Data    = oErrors;

                    return(Content(HttpStatusCode.BadRequest, oResponse));
                }

                var            claims    = ClaimsPrincipal.Current.Identities.First().Claims.ToList();
                string         UserId    = claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Sid, StringComparison.OrdinalIgnoreCase))?.Value;
                List <Account> oAccounts = oAccountManager.GetUserAccountsByUserId(Convert.ToInt32(UserId));

                if (!oAccounts.Where(m => m.AccountId == model.DebitAccountId).Select(c => c).Any())
                {
                    throw new ArgumentException("La cuenta a la que desea depositar no pertenece al usuario logeado");
                }
                ;

                CreditCardDetector detector = new CreditCardDetector(model.CreditCardNumber);

                if (!detector.IsValid())
                {
                    throw new ArgumentException("Los datos de la tarjeta de credito no son valdios");
                }

                oDepositManager.DepositWithCreditCard(model.Amount, model.DebitAccountId, model.FullName, model.CreditCardNumber.Substring(model.CreditCardNumber.Length - 4), model.DocumentNumber, model.ExpirationDate);
                oAccountManager.UpdateAccountBalance(model.DebitAccountId, model.Amount);

                oResponse.Success = 1;
                oResponse.Message = "Exito - se ha realizado el deposito correctamente";

                return(Content(HttpStatusCode.OK, oResponse));
            }
            catch (ArgumentException ex)
            {
                oResponse.Success = 0;
                oResponse.Message = "Error - no se ha podido realizar el deposito";
                oResponse.Data    = ex.Message;

                return(Content(HttpStatusCode.BadRequest, oResponse));
            }
            catch (Exception ex)
            {
                oResponse.Success = 0;
                oResponse.Message = "Error - no se ha podido realizar el deposito";
                oResponse.Data    = ex.Message;

                return(Content(HttpStatusCode.BadRequest, oResponse));
            }
        }
コード例 #3
0
        public IHttpActionResult Post([FromBody] TransferRequest model)
        {
            GeneralResponse oResponse        = new GeneralResponse();
            AccountManager  oAccountManager  = new AccountManager();
            TransferManager oTransferManager = new TransferManager();
            FieldsService   oFieldsService   = new FieldsService();

            var claims = ClaimsPrincipal.Current.Identities.First().Claims.ToList();

            string UserId = claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Sid, StringComparison.OrdinalIgnoreCase))?.Value;

            try
            {
                Dictionary <string, string> oErrors = oFieldsService.ValidateModel(ModelState);
                if (oErrors.Count != 0)
                {
                    oResponse.Success = 0;
                    oResponse.Message = "Error, campos invalidos";
                    oResponse.Data    = oErrors;

                    return(Content(HttpStatusCode.BadRequest, oResponse));
                }


                Account oDebitAccount = new Account();

                oDebitAccount = oAccountManager.GetAccountById(model.DebitAccountId);

                if (oDebitAccount.AccountId == null)
                {
                    throw new ArgumentException("Cuenta de debito no existente");
                }
                ;
                if (Convert.ToString(oDebitAccount.User.UserId) != UserId)
                {
                    throw new ArgumentException("No se puede transferir dinero desde una cuenta que no pertenece al usuario logeado");
                }
                ;
                if (oDebitAccount.Balance < model.Amount)
                {
                    throw new ArgumentException("No tiene el saldo suficiente para realizar esta transferencia");
                }
                ;

                Account oCreditAccount = new Account();
                oCreditAccount = oAccountManager.GetAccountById(model.CreditAccountId);

                if (oCreditAccount.AccountId == null)
                {
                    throw new ArgumentException("Cuenta de credito no existente");
                }
                ;

                oTransferManager.MakeTransfer(oDebitAccount, model.CreditAccountId, model.Amount, model.Concept);
                oAccountManager.UpdateAccountBalance((int)oDebitAccount.AccountId, -model.Amount);
                oAccountManager.UpdateAccountBalance(model.CreditAccountId, model.Amount);
                oResponse.Success = 1;
                oResponse.Message = "Exito - Transferencia realizada";

                return(Content(HttpStatusCode.OK, oResponse));
            } catch (ArgumentException ex)
            {
                oResponse.Success = 0;
                oResponse.Message = "Error - " + ex.Message;
                return(Content(HttpStatusCode.BadRequest, oResponse));
            } catch (Exception ex)
            {
                oResponse.Success = 0;
                oResponse.Message = ex.Message;
                return(Content(HttpStatusCode.BadRequest, oResponse));
            }
        }