コード例 #1
0
        public RecyclingBank Create(RecyclingBank entity)
        {
            using (SqlConnection connection = new SqlConnection(Connection.String))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "RecyclingBankCreate";

                command.Parameters.Add(new SqlParameter("@plastic", entity.Plastic));
                command.Parameters.Add(new SqlParameter("@paper", entity.Paper));
                command.Parameters.Add(new SqlParameter("@whiteGlass", entity.WhiteGlass));
                command.Parameters.Add(new SqlParameter("@colouredGlass", entity.ColouredGlass));
                command.Parameters.Add(new SqlParameter("@metal", entity.Metal));
                command.Parameters.Add(new SqlParameter("@capacity", entity.Capacity));
                command.Parameters.Add(new SqlParameter("@position", entity.Position));
                command.Parameters.Add(new SqlParameter("@creator", entity.Creator));

                connection.Open();
                int result = (int)command.ExecuteScalar();
                if (result < 1)
                {
                    throw new Exception("Error in CreateRecyclingBank stored procedure.");
                }

                entity.Id = (int)result;
                return(entity);
            }
        }
コード例 #2
0
        private RecyclingBank MapEntity(SqlDataReader data)
        {
            RecyclingBank result = new RecyclingBank();

            result.Id            = int.Parse(data["Id"].ToString());
            result.Plastic       = bool.Parse(data["Plastic"].ToString());
            result.Paper         = bool.Parse(data["Paper"].ToString());
            result.WhiteGlass    = bool.Parse(data["WhiteGlass"].ToString());
            result.ColouredGlass = bool.Parse(data["ColouredGlass"].ToString());
            result.Metal         = bool.Parse(data["Metal"].ToString());
            result.Capacity      = int.Parse(data["Capacity"].ToString());
            result.Position      = data["Position"].ToString();
            result.Creator       = data["Creator"].ToString();
            result.CreateDate    = DateTime.Parse(data["CreateDate"].ToString());

            return(result);
        }
コード例 #3
0
        public ResponseMessage <RecyclingBank> Create(RecyclingBankCreateRequest data, string uniq)
        {
            ResponseMessage <RecyclingBank> response = new ResponseMessage <RecyclingBank>();

            try
            {
                RecyclingBank user = new RecyclingBank(data, uniq.Reverse());

                response.ResponseObject = _recyclingBankRepository.Create(user);
                response.IsSuccess      = true;
                response.ErrorMessage   = "Success";
            }
            catch (Exception ex)
            {
                response.IsSuccess    = false;
                response.ErrorMessage = ex.Message;
            }

            return(response);
        }