Ejemplo n.º 1
0
        protected ActionResult <T> HandleResponse <T>(DataAccessResponse <T> response)
        {
            if (response == null)
            {
                return(BadRequest(new NullReferenceException("The data access response is null!")));
            }

            switch (response.Status)
            {
            case HttpStatusCode.OK:
                return(Ok(response.Payload));

            case HttpStatusCode.NotFound:
                return(NotFound());

            case HttpStatusCode.Created:
                return(Created(response.Payload as string, response.Payload));

            case HttpStatusCode.NoContent:
                return(NoContent());

            case HttpStatusCode.InternalServerError:
                return(new StatusCodeResult(500));

            default:
                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DataAccessResponse          Response = null;
            List <TransactionParameter> TransactionParameters = new List <TransactionParameter>();

            TransactionParameters.Add(new TransactionParameter()
            {
                DataType = DataTypeEnum.STRING, Value = "Vinod"
            });
            TransactionParameters.Add(new TransactionParameter()
            {
                DataType = DataTypeEnum.STRING, Value = "Kumar"
            });
            TransactionParameters.Add(new TransactionParameter()
            {
                DataType = DataTypeEnum.STRING, Value = "Gupta"
            });
            DataAccessRequest Request = new DataAccessRequest()
            {
                SecurityParameter = new SecurityParameter()
                {
                    UserID        = "VGupta",
                    OperationCode = OperationCodeEnum.GET_USER
                },
                TransactionParameters = TransactionParameters,
            };

            using (DataAccessFacade facade = new DataAccessFacade())
            {
                Response = facade.Exceute(Request);
            }
        }
Ejemplo n.º 3
0
        public async Task <DataAccessResponse> ExecuteNonQuery(SqlCommand sqlCommand)
        {
            var response = new DataAccessResponse();

            try
            {
                using (var connection = new SqlConnection(this.connectionProvider.DBConnection))
                {
                    connection.Open();

                    using (this.transaction = connection.BeginTransaction())
                    {
                        sqlCommand.Connection  = connection;
                        sqlCommand.Transaction = this.transaction;
                        var result = await sqlCommand.ExecuteNonQueryAsync();

                        this.transaction.Commit();
                        response.Message = $"Succesfully executed {sqlCommand.CommandText}";
                        response.Success = true;
                    }

                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                this.transaction.Rollback();
                response.Errors.Add(ex.Message);
                response.Message = $"Failed to Execute Non Query Command : {sqlCommand.CommandText}.";
            }

            return(response);
        }
Ejemplo n.º 4
0
 public StubUserDataAccess(DataAccessResponse response)
 {
     this.response = new DataAccessResponse
     {
         Success = true,
         Message = "Successful Execution of query"
     };
 }
Ejemplo n.º 5
0
 public static DataAccessResponse <string> ToModel(this DataAccessResponse <string> response)
 {
     if (response == null || response.Payload == null)
     {
         return(null);
     }
     return(new DataAccessResponse <string>(response.Payload, response.Status));
 }
Ejemplo n.º 6
0
 public static DataAccessResponse <Models.Friend> ToModel(this DataAccessResponse <Entities.Friend> response)
 {
     if (response == null || response.Payload == null)
     {
         return(null);
     }
     return(new DataAccessResponse <Models.Friend>(response.Payload.ToModel(), response.Status));
 }
Ejemplo n.º 7
0
        public DataAccessResponse <string> CreateUser(Dto.ApplicationUser userDto, string password, bool isAuthor)
        {
            var resp = new DataAccessResponse <string> {
                ResponseCode = ResponseCode.Fail
            };

            bool userExists = true;

            if (string.IsNullOrEmpty(userDto.Email))
            {
                userExists = _db.Users.Any(u => u.UserName == userDto.UserName);
            }
            else
            {
                userExists = _db.Users.Any(u => u.UserName == userDto.UserName || u.Email == userDto.Email);
            }

            if (userExists)
            {
                resp.ResponseMessage = ErrorMessage.UserExists;
                return(resp);
            }

            var userModel = new ApplicationUser
            {
                NameSurname      = userDto.NameSurname,
                Email            = userDto.Email ?? "",
                EmailConfirmed   = userDto.EmailConfirmed,
                PhoneNumber      = userDto.PhoneNumber,
                UserName         = userDto.UserName,
                Status           = userDto.Status,
                TwoFactorEnabled = userDto.ContactPermission, // contact permission field matched with twoFactorEnabled column
                PasswordHash     = HashPassword(password),
                SecurityStamp    = Guid.NewGuid().ToString()
            };

            var newUser = _db.Users.Add(userModel);

            //if (isAuthor)
            //{
            //    var role = new IdentityUserRole
            //    {
            //        UserId = newUser.Id,
            //        RoleId = DatabaseKey.ApplicationRoleId.Author
            //    };
            //    newUser.Roles.Add(role);
            //}
            _db.SaveChanges();

            resp.ResponseCode = ResponseCode.Success;
            resp.ResponseData = newUser.Id;

            return(resp);
        }
Ejemplo n.º 8
0
        public DataAccessResponse Exceute(DataAccessRequest DataAccessRequest)
        {
            DataAccessResponse Response = null;

            try
            {
                DataTable SecurityDataTable;
                DataTable ParameterDataTable;

                DataAccessConfiguration DataAccessConfig = (DataAccessConfiguration)ConfigurationManager.GetSection("DataAccessConfiguration");
                using (DataAccessManager Manager = new DataAccessManager(DataAccessRequest, DataAccessConfig))
                {
                    SecurityDataTable  = Manager.BuildSecurityDataTable();
                    ParameterDataTable = Manager.BuildParameterDataTable();
                    Response           = Manager.BuildResponse(ParameterDataTable);
                }
            }
            catch (DataAccessException Exception)
            { }
            return(Response);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// ParameterTable has to be updated for the values which are set in configuration table
        /// </summary>
        /// <returns></returns>



        internal DataAccessResponse BuildResponse(DataTable parameterDataTable)
        {
            DataAccessResponse Response        = null;
            DataTable          ResultDataTable = null;
            //Thought-1
            //The parameterDataTable table contains parameter values in rows while these values need to be converted in column
            //then only the data table can be passed to stored procedure
            //Thought-2
            //No, let me not do this because of the following problem
            //1. If I convert rows into columns then I cannot use the data table as a parameter to stored procedure because
            //I cannot create a user defined table data type which can satisfy variable number of columns. In this original table I have
            //fixed number of columns so it will be easy for me to create the user defined type for data table parametr to pass as input
            //parameter to stored procedure
            //Thoght-3
            //But the limitation of this final(unchanged) approach is that one parameter can contain only one value
            //Because the parameters are stored in form of rows in this data table so there would be only one value column
            //created in PopulateParameterValuesInTransformedParameterTable method....huh, this is not what I wanted.
            //O...hold on, if I add a Sequence column in data table then I can address this problem. I can repeat the set of
            //parameters multiple times assigning unique sequence value for one set....cool, i got the solution
            //No, it did not work, I have received an exception in DataAccessConfiguration class saying thet the item is already
            //added into the collection, let me park this aside for now and complete the limited functionality
            //I think, I dont have to add anything into the DataAccessConfiguration section of configuration file, I can manage with the
            //values I receive in the _dataAccessRequest object
            DataTable TransformedParameterDataTable = TransformParameterTable(parameterDataTable);

            //Thought-1
            //Now, since the above method returned the transformed data table so we can fill the parameter values
            //Thought-2
            //Since I have not changed the original table at all, so let me extend this data table by adding a column for
            //capturing the value of each parameter
            TransformedParameterDataTable = PopulateParameterValuesInTransformedParameterTable(TransformedParameterDataTable);

            using (DatabaseManager DBManager = new DatabaseManager(TransformedParameterDataTable))
            {
                ResultDataTable = DBManager.PopulateParameterResultTable();
            }

            return(Response);
        }
Ejemplo n.º 10
0
        public DataAccessResponse ResetPassword(string userId, string password)
        {
            var resp = new DataAccessResponse
            {
                ResponseCode = ResponseCode.Fail
            };

            var userModel = _db.Users.FirstOrDefault(u => u.Id == userId);

            if (userModel == null)
            {
                return(resp);
            }

            userModel.PasswordHash = HashPassword(password);

            _db.Entry(userModel).State = System.Data.Entity.EntityState.Modified;

            _db.SaveChanges();

            resp.ResponseCode = ResponseCode.Success;

            return(resp);
        }
        public async Task <ActionResult <IEnumerable <PurchasedItem> > > Get(string friendId)
        {
            DataAccessResponse <IEnumerable <PurchasedItem> > response = await _service.GetAll(friendId);

            return(HandleResponse(response));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <Friend> > Get(string id)
        {
            DataAccessResponse <Friend> response = await _service.Get(id);

            return(HandleResponse(response));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <string> > Post([FromBody] Friend friend)
        {
            DataAccessResponse <string> response = await _service.Add(friend);

            return(HandleResponse(response));
        }
Ejemplo n.º 14
0
 public static DataAccessResponse <IEnumerable <Models.PurchasedItem> > ToModel(this DataAccessResponse <IEnumerable <Entities.PurchasedItem> > response)
 {
     if (response == null || response.Payload == null)
     {
         return(null);
     }
     return(new DataAccessResponse <IEnumerable <Models.PurchasedItem> >(response.Payload.ToModel(), response.Status));
 }
Ejemplo n.º 15
0
        public async Task <ActionResult <string> > Delete(string id)
        {
            DataAccessResponse <string> response = await _service.Remove(id);

            return(HandleResponse(response));
        }
Ejemplo n.º 16
0
        internal DataAccessResponse ExcuteOperation()
        {
            DataAccessResponse DataAccessResponse = null;

            return(DataAccessResponse);
        }
        public async Task <ActionResult <string> > Delete(string friendId, Guid purchasedItemId)
        {
            DataAccessResponse <string> response = await _service.Remove(friendId, purchasedItemId);

            return(HandleResponse(response));
        }
        public async Task <ActionResult <string> > Put(string friendId, Guid purchasedItemId, [FromBody] PurchasedItem purchasedItem)
        {
            DataAccessResponse <string> response = await _service.Update(friendId, purchasedItemId, purchasedItem);

            return(HandleResponse(response));
        }
        public async Task <ActionResult <PurchasedItem> > Get(string friendId, Guid purchasedItemId)
        {
            DataAccessResponse <PurchasedItem> response = await _service.Get(friendId, purchasedItemId);

            return(HandleResponse(response));
        }
Ejemplo n.º 20
0
        public async Task <ActionResult <IEnumerable <Friend> > > Get()
        {
            DataAccessResponse <IEnumerable <Friend> > response = await _service.GetAll();

            return(HandleResponse(response));
        }