Beispiel #1
0
        // GET: Users/GetUser/GetUserRequest
        public GetUserResponse GetUser([FromBody] GetUserRequest request)
        {
            if (!ModelState.IsValid)
            {
                throw new System.Exception(ModelState.ErrorCount.ToString());
            }

            CibitDb context = HttpContext.RequestServices.GetService(typeof(CibitDb)) as CibitDb;;

            var config   = new MapperConfiguration(mc => mc.CreateMap <GetUserRequest, UserDTO>());
            var mapper   = new Mapper(config);
            var userinfo = mapper.Map <GetUserRequest, UserDTO>(request);

            var spObj = Converters.GetUserConverter(userinfo);

            var reader = context.StoredProcedureSql("getUser", spObj);

            GetUserResponse response = new GetUserResponse();

            while (reader.Read())
            {
                response.user = new User()
                {
                    CibitId    = reader["cibitId"].ToString(),
                    FName      = reader["fName"].ToString(),
                    LName      = reader["lName"].ToString(),
                    Email      = reader["email"].ToString(),
                    University = reader["university"].ToString()
                };
            }

            context.Connection.Close();
            return(response);
        }
Beispiel #2
0
        // INSERT: Research/CreateResearch/CreateResearchRequest
        public bool CreateResearch([FromBody] CreateResearchRequest request)
        {
            CibitDb context = HttpContext.RequestServices.GetService(typeof(CibitDb)) as CibitDb;

            var config   = new MapperConfiguration(mc => mc.CreateMap <CreateResearchRequest, ResearchDTO>());
            var mapper   = new Mapper(config);
            var userinfo = mapper.Map <CreateResearchRequest, ResearchDTO>(request);

            var spObj  = Converters.CreateResearchConverter(userinfo);
            var reader = context.StoredProcedureSql("CreateReasarch", spObj);

            context.Connection.Close();
            return(true);
        }
Beispiel #3
0
        // DELETE: Transaction/RemoveCoin/RemoveCoinRequest
        public bool RemoveCoin([FromBody] RemoveCoinRequest request)
        {
            CibitDb      context = HttpContext.RequestServices.GetService(typeof(CibitDb)) as CibitDb;
            ValidateUser valid   = new ValidateUser();

            var config   = new MapperConfiguration(mc => mc.CreateMap <RemoveCoinRequest, TransactionDTO>());
            var mapper   = new Mapper(config);
            var userinfo = mapper.Map <RemoveCoinRequest, TransactionDTO>(request);

            valid.VerifyCoinId(userinfo.CoinId, userinfo.SenderId);

            var spObj  = Converters.RemoveCoinConverter(userinfo);
            var reader = context.StoredProcedureSql("RemoveCoin", spObj);

            context.Connection.Close();
            return(true);
        }
Beispiel #4
0
        // GET: Users/GetAllUsers/
        public GetAllUsersResponse GetAllUsers()
        {
            CibitDb context = HttpContext.RequestServices.GetService(typeof(CibitDb)) as CibitDb;;

            var reader = context.StoredProcedureSql("getUsers", null);

            GetAllUsersResponse response = new GetAllUsersResponse();

            while (reader.Read())
            {
                response.Users.Add(new User()
                {
                    CibitId        = reader["cibitId"].ToString(),
                    FName          = reader["fName"].ToString(),
                    LName          = reader["lName"].ToString(),
                    Email          = reader["email"].ToString(),
                    University     = reader["university"].ToString(),
                    CitationAmount = (int.TryParse(reader["citationAmount"].ToString(), out int number)) ? number : 0
                });